2 different SPI devices and Exceeded blocks

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

So I have added another SPI component to my application and now how Exceeded blocks.  I found that I can just use a Control Register to switch between CS pins, but the issue is that one component accepts a 16-bit and the other is an 8-bit.  Question is, how to I send just the 8 bits when the SPI component is set to accept 16?

0 Likes
1 Solution
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

You can configure the SPI for 8 bits and just send 2 bytes to the SPI slave that accepts 16 bits. Just control the CS signals manually (with a control register), and not via the SPI master.

View solution in original post

0 Likes
3 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

You can configure the SPI for 8 bits and just send 2 bytes to the SPI slave that accepts 16 bits. Just control the CS signals manually (with a control register), and not via the SPI master.

0 Likes
Anonymous
Not applicable

Thank you.  I've decided to take a different route, but the same issue/solution arises now.  I'm no longer implementing 2 SPI devices, but the 16-bit one is still in play and I'm getting the same error as a 16-bit transfer, so I'll need to use 8-bit, and send 2 bytes.  No more error, but now I think I have a coding issue as to how to send 2 bytes. More so, how to correctly define variable perhaps.  Below is my transfer function. buffSend is interpreted as 'uint8 cmdBuffer[SWITCHBUFF]', SWITCHBUFF being defined as 2u.  cmdBuffer[0] is the command byte, and cmdBuffer[1] is a data byte.  All of each are defined as 0x0#...0xF0, etc.  In debug, it gets stuck here: size = (0u != (SPI_Switch_RX_STATUS_REG & SPI_Switch_STS_RX_FIFO_NOT_EMPTY)) ? 1u : 0u;

   

static void switchCommand(uint32 cmd, uint32 data){
        static uint8 bufferOut[SWITCHBUFF] = {CLICKM_CMD,CLICKLESS_CMD};
        bufferOut[CMD_INDEX] = (uint8)cmd;
        bufferOut[DATA_INDEX] = (uint8)data;      
        SPI_Switch_PutArray(bufferOut, SWITCHBUFF);
        while (SWITCHBUFF != SPI_Switch_GetRxBufferSize())
        {
        }
        SPI_Switch_ClearRxBuffer();
        CyDelay(5u);        
}

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Do you clear the RX buffer before this code? Otherwise it might not be empty, and then your check is invalid.

   

You can also check the TX status for not being IDLE.

0 Likes