This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nrf52840 SPIM0 consecutive TX bug

Hi,

I am writing my own SPIM driver, when I try to send a 2 bytes message and then a 26 bytes message the second message "crashes" after 2 bytes.

But if I send the 26 bytes message and then the 2 bytes message, the two messages are correctly sent.

Any known issue with TXD.MAXCNT ?

My code :

#define FLAG_CLEAR() 	NRF_SPIM0->EVENTS_ENDRX = 0;\
						NRF_SPIM0->EVENTS_ENDTX = 0;\
						NRF_SPIM0->EVENTS_STARTED = 0;\
						NRF_SPIM0->EVENTS_STOPPED = 0;\
						NRF_SPIM0->EVENTS_END = 0;

void SPI_setup()
{
	NRF_SPIM0->ENABLE = 0;
	
	NRF_SPIM0->PSEL.SCK = (SPI0_CLK_Port<<5UL) + SPI0_CLK_Pin;
	NRF_SPIM0->PSEL.MISO = (SPI0_MISO_Port<<5UL) + SPI0_MISO_Pin;
	NRF_SPIM0->PSEL.MOSI = (SPI0_MOSI_Port<<5UL) + SPI0_MOSI_Pin;
	NRF_SPIM0->FREQUENCY = SPIM_FREQUENCY_FREQUENCY_M2;
	NRF_SPIM0->CONFIG = SPIM_CONFIG_CPHA_Msk;
	
	NRF_SPIM0->ENABLE = SPIM_ENABLE_ENABLE_Enabled;                           
}

void SPI_write(void* data, uint32_t length)
{
	NRF_SPIM0->RXD.MAXCNT = 0;
	NRF_SPIM0->TXD.PTR = (uint32_t)data;
	NRF_SPIM0->TXD.MAXCNT = length;
	NRF_SPIM0->TASKS_START = 1;
	while(NRF_SPIM0->EVENTS_ENDTX == 0);
	NRF_SPIM0->TASKS_STOP = 1;
	FLAG_CLEAR();
}

When I send 2b and then 26b, you can see the weird crash with additional clock edges...

logicscreenshot

Parents Reply Children
  • Hi,

    Could you share the exact code that shows where the length is defined and how SPI_write() is called. 

    Or can you check with a debugger if TXD.MAXCNT is actually 26 at the second transfer ?

    Regards,
    Jonathan

  • I checked, TXD.MAXCNT = 26 and TXD.AMOUNT = 2 when the crash occurs, but I get stuck in the while.

    I am not sure if the problem comes from the uC side, I fixed the problem by adding CS edges between messages. So it is maybe related to the component (ADS1298) but I was using this driver(with no CS edges) with a STM32H7 microcontroller and it worked well. As the nrf52 is the SPI master, I still can't explain this issue, perhaps timing issue ?

Related