Hi everyone,
I'm trying to communicate uC and accelerometer, but I am not able to.This is how I configure SPI using Device Initialization:
/* ### Init_SPI init code */ /* SPICR1: SPIE=0,SPE=0,SPTIE=0,MSTR=0,CPOL=0,CPHA=0,SSOE=0,LSBFE=0 */ SPICR1 = 0U; /* Disable the SPI module and clearing flags in SPISR register */ /* SPICR2: XFRW=0,MODFEN=0,BIDIROE=0,SPISWAI=0,SPC0=0 */ SPICR2 = 0U; /* SPIBR: SPPR2=0,SPPR1=0,SPPR0=0,SPR2=0,SPR1=0,SPR0=0 */ SPIBR = 0U; /* SPICR1: SPIE=0,SPE=1,SPTIE=0,MSTR=1,CPOL=0,CPHA=0,SSOE=0,LSBFE=0 */ SPICR1 = 80U;
And this is example of writing to SPI slave device:
void acc_write_reg(byte reg, byte val) { byte x; ACC_SPI_CS =0;
while (!SPISR_SPIF); //wait for transmission completex=SPIDRL; //dummy readSPIDRL= val ;while (!SPISR_SPIF); //wait for transmission completex=SPIDRL; ACC_SPI_CS = 1; }
But while debbuging I saw that this part:
x =((reg << 1) | 0x80); SPIDR = x;
resultes with 0xFF SPIDR value. And no matter what I put there, it doesn't change. What do I do wrong?
I'll be grateful for any help!
Michael