This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1101: CC1101 packet length iterations in the code

Part Number: CC1101

Hi

I am just trying to visualize the TX/RX packet journey through the source code, I have been checking many available codes and there is something

I find it hard to comprehend, what are the usage of the for loop iteration at some stages of TX and RX as in the following samples;

for(uint8_t i = 0 ; i < pktlen + 1; i++)
{
uart_puthex_byte(rxbuffer[i]);
}
Serial.print(" |");
uart_puthex_byte(rxbuffer[pktlen+1]);

uart_puthex_byte(rxbuffer[pktlen+2]);

Serial.print(F("RX_FIFO:"));

and,

writeSPI(0xFF); // burst read adresse


MOSIOUT &= ~MOSI; 


for(i=1; i<(len+1); i++){

data[i] = readSPI();

}

Kind Regards

Mustafa

  • Hi Mustafa

    It is not possible to answer your question without knowing which code you are referring to. If you have questions to any of the examples code that TI provides for the CC1101 device, please let me know which code examples you are referring to (also which files and function), and I will explain what the code is doing.

    If I should guess, you are looking at examples that uses the standard packet format and recommended settings for the CC1101.

    When you receive a packet in the RX FIFO, the first byte in the FIFO will be the length byte (called pktlen or len in the code you are showing). This length byte will be followed by len or pktlen payload bytes, and after that there will be 2 status bytes:

    for example:

    pktlen = 5

    Payload = AA, BB, CC, DD, EE

    Status bytes: 0xXX, 0xXX

    In the FIFO you will have: 0x05, 0xAA, 0xBB; 0xCC, 0xDD, 0xEE, 0xXX, 0xXX

    The length byte is in rxbuffer[0], payload in rxbuffer[1] - rxbuffer[pktlen], and the status bytes in rxbuffer[pktlen + 1] and rxbuffer[pktlen + 2]

    Siri

  • Hi Siri

    my question is not about a particular code, it is about why the packet length should get incremented ++1, for a certain number  of times in any code.

    Kind Regards

    Mustafa

  • The packet length is not incremented in any of the code examples you are referring to. The variable "i" is what is incremented (i++)

    In both cases, the packet length is used to find out on which index in the buffer the packet is stored:

    Example 1: rxbuffer[] = {5, 10, 20, 30, 40, 50, status1, staus0}

    The length is at index 0 and is 5 (pktlen = 5)

    You then know that the last byte in the packet will be in rxbuffer[5], and the status bytes will be at rxbuffer[6] and rxbuffer[7].

    This will only be true if the length byte = 5, but what will always be true is that the last byte of the packet is at rxbuffer[pktlen] , and that the status bytes will be at rxbuffer[pktlen + 1] and rxbuffer[pktlen + 2].

    Siri

  • Hi Siri

    maybe my question was not clear enough for you but you guessed and your replies holding the exact full answers I was after, thanks a lot.

    Kind Regards

    Mustafa