Hi,
I want to read a IC register over SPI.
This is msp430 code,it works. Just
CS low
write address
write 0x00
CS high
void bmx_spi_read(uint8_t addr,uint8_t *data)
{
P1OUT &= ~BMX_cs;
__delay_cycles(100);
while(!(IFG2&UCB0TXIFG));
UCB0TXBUF = addr;
while(!(IFG2&UCB0TXIFG));
UCB0TXBUF = 0x00;
while(!(IFG2&UCB0RXIFG));
*data = UCB0RXBUF;
__delay_cycles(100);
P1OUT |= BMX_cs;
}
I use SPIM, this is initialization
NRF_SPIM0->PSEL.SCK = bmx_sck; NRF_SPIM0->PSEL.MOSI = bmx_mosi; NRF_SPIM0->PSEL.MISO = bmx_miso; NRF_SPIM0->FREQUENCY = SPIM_FREQUENCY_FREQUENCY_M1 << SPIM_FREQUENCY_FREQUENCY_Pos; NRF_SPIM0-> ENABLE = SPIM_ENABLE_ENABLE_Enabled << SPIM_ENABLE_ENABLE_Pos; uint8_t bmx_id=0; NRF_GPIO->OUTCLR = (1UL << bmx_cs1); dly = 1000; while(dly--); bmx_id=spi_read(0x00); dly = 1000; while(dly--); NRF_GPIO->OUTSET = (1UL << bmx_cs1);
this is spi read function
uint8_t spi_read(uint8_t addr)
{
uint8_t tx_buf[2];
uint8_t rx_buf[1];
NRF_SPIM0->SHORTS = SPIM_SHORTS_END_START_Msk;
tx_buf[0] = addr;
tx_buf[1] = 0x00;
NRF_SPIM0->TXD.MAXCNT = sizeof(tx_buf);
NRF_SPIM0->TXD.PTR = (uint32_t)&tx_buf[0];
NRF_SPIM0->RXD.MAXCNT = 1;
NRF_SPIM0->RXD.PTR = (uint32_t)&rx_buf[0];
NRF_SPIM0->EVENTS_STOPPED = 0;
NRF_SPIM0->TASKS_START = 1;
while (NRF_SPIM0->EVENTS_STOPPED == 0);
return rx_buf[0];
}
I test it debug mode and the code stucks at while (NRF_SPIM0->EVENTS_STOPPED == 0); line
For generate 16 clock cycles, i need to write extra 0x00 bytes in msp430.
TX and RX operations works simultaneously like MSP430?
Read diagram should be like below.

