Site icon volt.tech

SCI_SPI delays

I am implementing some low level functions for the library (for the CLRC663 NFC reader chip) I am going to write, based on  that Simple SPI communication, but I see something weird.

void CLRC663_write_regs(uint8_t reg, const uint8_t* values, uint8_t len) {

uint8_t tempBuf[len+1], i;

tempBuf[0] = reg;
for (i = 1; i < len+2; i++) tempBuf[i] = values[i-1];

g_transfer_complete = false;
CLRC663_enable();

R_SCI_SPI_Write(&g_spi0_ctrl, &tempBuf, sizeof(tempBuf), SPI_BIT_WIDTH_8_BITS);
while (!g_transfer_complete);

CLRC663_disable();
}

and calling it on the main with this:

CLRC663_write_regs(0x02,&g_master_tx_buff,4);

(consider that g_master_tx_buff is filled with  0xAA, 0xBB, 0xCC, 0xDD)

I have these waveforms:

Consider that the SCI callback is simply:

void sci_spi_callback(spi_callback_args_t *p_args) {
if (SPI_EVENT_TRANSFER_COMPLETE == p_args->event) {
g_master_event_flag = SPI_EVENT_TRANSFER_COMPLETE;
g_transfer_complete = true;
} else {
/* Updating the flag here to capture and handle all other error events */
g_master_event_flag = SPI_EVENT_TRANSFER_ABORTED;
}
}

and the enable/disable function are simple i/O controls

void CLRC663_enable (void) {
R_IOPORT_PinWrite(&g_ioport_ctrl, SPI_SSLA0, BSP_IO_LEVEL_LOW);
}

void CLRC663_disable (void) {
R_IOPORT_PinWrite(&g_ioport_ctrl, SPI_SSLA0, BSP_IO_LEVEL_HIGH);
}

The question is: why I got such delays after CS goes low? And why I got about the same delay when I put the CS high?

Exit mobile version