Tool/software: Code Composer Studio
| eCOM LSM303AGR |
|-----P3.5---->|CS_ACC Pin 2 |
|-----P3.4---->|CS_MAG Pin 3 |
|-----P3.3---->|SDI/O Pin 4 |
|-----P2.7---->|SCLK Pin 1 |
|<----P2.6-----|INT_2_ACC Pin 11 |
|<----P2.5-----|INT_1_ACC Pin 12 |
|<----P2.0-----|INT_MAG Pin 7 |
Is it possible to initialize the SPI for an interface to the eCom
when SIMO and SOMI are both on the same pin?
Only one CS can be active.
I always get 0xFF in the UCA0RXBUF
uint8_t eComACC_ReadReg(uint8_t RegNum) {
Reg = (RegNum & 0x3F);
Reg |= 0x80; // Turn on read, Turn off the multiple data bit
P3OUT &= ~BIT5; // Select acceleration sensor
Result = UCA0RXBUF; // Read RX buffer just to clear interrupt flag
while (!(UCA0IFG & UCTXIFG)); // Wait until ready to write
UCA0TXBUF = Reg; // Write Address to TX buffer
while (!(UCA0IFG & UCRXIFG)); // Wait until new data was written into RX buffer
Result1 = UCA0RXBUF; // Read RX buffer just to clear interrupt flag
while (!(UCA0IFG & UCTXIFG)); // Wait until ready to write
UCA0TXBUF = 0x00; // Write dummy data to TX buffer
while (!(UCA0IFG & UCRXIFG)); // Wait until new data was written into RX buffer
Result2 = UCA0RXBUF; // Read RX buffer
while (UCA0STAT & UCBUSY); // Wait until USCI_A0 state machine is no longer busy
P3OUT |= BIT5;
return Result2; // Return new data from RX buffer
}
void eComACC_WriteReg(uint8_t RegNum, uint8_t AccData) {
RegNum &= 0x3F; // Set for write, Turn off the multiple write bit
P3OUT &= ~BIT5; // Select acceleration sensor
Result = UCA0RXBUF; // Read RX buffer just to clear interrupt flag
while (!(UCA0IFG & UCTXIFG)); // Wait until ready to write
UCA0TXBUF = RegNum; // Write Reg to TX buffer
while (!(UCA0IFG & UCRXIFG)); // Wait until new data was written into RX buffer
Result = UCA0RXBUF; // Read RX buffer just to clear interrupt flag
while (!(UCA0IFG & UCTXIFG)); // Wait until ready to write
UCA0TXBUF = AccData; // Write data to TX buffer
while (!(UCA0IFG & UCRXIFG)); // Wait until new data was written into RX buffer
Result = UCA0RXBUF; // Read RX buffer
while (UCA0STAT & UCBUSY); // Wait until USCI_A0 state machine is no longer busy
P3OUT |= BIT5;
}