Hello all
I had recently to implement SPI communication between MSP430 and ADS1158. That's my almost first experience with SPI therefore I'm not sure if my method is correct (Though it gives me correct results.). Could you please confirm If I'm using correct procedure?
SPI configuration I'm using is:
UCB0CTL0 = UCCKPH+UCMST+UCSYNC+UCMSB;
UCB0CTL1 = UCSSEL_2;
UCB0BR0 = 0x02; /*Bit rate divider, LB = divide clock by 2 = 4MHz*/
UCB0BR1 = 0;
MCLK is 8 MHz from DCO using calibrated values, ADS1158 uses 32kHz crystal. CS is tied to low .
In order to send/receive bytes via SPI I'm using following procedure:
while(!(IFG2 & UCB0TXIFG));
UCB0TXBUF = ucValue; // Either value to send or dummy byte
while(!(IFG2 & UCB0RXIFG));
ucResult = UCB0RXBUF; // or just IFG2 &= ~(UCB0RXIFG) to reset RX flag if getting don't care data
Then I just repeat 4 operations above until I get all data I want.
Is it correct to wait for UCB0RXIFG always after I have transmitted command byte or dummy byte (to receive data)? I've seen SPI implementation waiting only for UCB0TXIFG, but such version didn't work for ADS1158 well.
The procedure above gives me always correct results, but I noticed that it takes around 35us to get channel data in register format whereby it should take around 6us theoretically (at 4 MHz SPI). I tried to investigate this, but oscilloscope I was using wasn't good enough to represent 2 channels simultaneously. Though I noticed that there is a pause in UCLK after each transmitted byte. Any idea what could cause such behavior?