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.

CC1101EM868-915_REFDES: Should the first byte of tx buffer be length byte ?

Part Number: CC1101EM868-915_REFDES
Other Parts Discussed in Thread: CC1101

Hi;

I do not want to send the lenght of my buffer. I just want to send exactly my buffer but on my code if ı do not send a size of my buffer first  and even if I change the inside of my buffer, it continues to send old data. Even  PKTCTRL0  (Packet automation control) is "0x05",it is meaning Infinite packet length mode. So ı do not need to send a size of buffer. But my problem is lets say ı am sending a fener[26] buffer and ı delete the send a size of buffer on  cc1101_send_packet function and change the sending data lets say ı made packet[26]  and reload program again but it still send old(fener[26]) data. but when ı open the sending size function in cc1101_send_packet function 

My codes;

void SpiCWriteBurstReg(uint8_t Addr,uint8_t *Buffer,uint8_t Count)
{
uint8_t i=0;
uint8_t temptxburst[Count+2];
HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_RESET);
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6) != GPIO_PIN_RESET);
// temptxburst[0] = SPI_ReadWrite(Addr|WRITE_BURST); // adreside yanlislikla yazdirdigim yer.
temptxburst[0] = Addr|WRITE_BURST;
HAL_SPI_Transmit(&hspi1,&temptxburst[0],1,10);

HAL_SPI_Transmit(&hspi1,Buffer,Count,10); // DATA TOPLU GONDERIM

HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_SET);
}

void SPiCWriteReg(uint8_t Addr,uint8_t Value)
{
// SPiCPowerUpReset();
Power_up_reset();
uint8_t Data_Write[2];
Data_Write[0]=Addr;
Data_Write[1]=Value;
HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_RESET);
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6) != GPIO_PIN_RESET);
HAL_SPI_Transmit(&hspi1,Data_Write,2,10);
HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_SET);
}

void SpiCStrobe(uint8_t Strobe)
{
HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_RESET); //CS enable
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6) != GPIO_PIN_RESET);
SPI_ReadWrite(Strobe);
HAL_GPIO_WritePin(SPI1_CSn_GPIO_Port, SPI1_CSn_Pin, GPIO_PIN_SET); //CS disable
}

void cc1101_send_packet(uint8_t* txBuffer, uint8_t size)
{

SpiCStrobe(CCxxx0_SIDLE);

SPiCWriteReg(CCxxx0_TXFIFO, size);   //I DO NOT WANT TO SEND SIZE . when i close this program is not working correctly.

SpiCWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size);

SpiCStrobe(CCxxx0_STX);
}

uint8_t DataBufferX1[26]= {0x19, 0x44, 0x55, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x65, 0x20, 0x54, 0x75, 0x72, 0x61, 0x6E, 0x20, 0x20, 0x43, 0x43, 0x31, 0x31, 0x30, 0x31, 0x20}; 
uint8_t fener[26] = {0x66, 0x65, 0x6e, 0x65, 0x72, 0x62, 0x61, 0x68, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x6b, 0x20, 0x79, 0x61, 0x73, 0x61, 0x20, 0x6f, 0x6f, 0x6f, 0x6c, 0x65, 0x79};
uint8_t packet[26] = {0x43, 0x43, 0x31, 0x31, 0x30, 0x31, 0x20, 0x74, 0x61, 0x6d, 0x61, 0x6d, 0x6c, 0x61, 0x6e, 0x64, 0x69, 0x20, 0x59, 0x45, 0x53, 0x53, 0x53, 0x21, 0x21, 0x21};


while (1)
{
HAL_Delay(500);
SpiCStrobe(CCxxx0_SFTX); 

cc1101_send_packet(fener,26 ); 

while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_2) == GPIO_PIN_SET);// while(HAL_GPIO_ReadPin(GDO0_GPIO_Port, GDO0_Pin));
while(HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_2) != GPIO_PIN_SET);// while(!HAL_GPIO_ReadPin(GDO0_GPIO_Port, GDO0_Pin));

}

  • Hi

    I do not understand your comment:

    "Even  PKTCTRL0  (Packet automation control) is "0x05",it is meaning Infinite packet length mode."

    PKTCTRL0 = 0x05 does not mean infinite packet length mode but means Variable packet length mode (Packet length configured by the first byte after sync word)

    In this case the radio will interpret the first byte you write to the TXFIFO as the length byte, and it will try to send as many bytes as indicated by the length.

    If you use variable packet length mode, and write 0x01, 0x02, 0x03, 0x04, 0x05 to the TX FIFO, the 0x01 will be interpret as the length, and only 0x01, and 0x02 will be sent (0x03, 0x04, 0x05 will be left in the FIFO, and the next time you try to send something (if you are not flushing the FIFO), the 0x03 is the first byte in the FIFO and it will be the length.

    If you only want to transmit 0x01, 0x02, 0x03, 0x04, 0x05, you need to use Fixed packet length mode (PKTCTRL0 = 0x04), and set PKTLEN = 5 (number of bytes you want to send)

    Siri

  •  I do not want to send variable length. I just want to send a my data.

  • If you do not want to send the length, you do what I just explained:

    "If you only want to transmit 0x01, 0x02, 0x03, 0x04, 0x05, you need to use Fixed packet length mode (PKTCTRL0 = 0x04), and set PKTLEN = 5 (number of bytes you want to send)"

    Write the data you want to send to the TX FIFO, and set PKTLEN to the number of bytes you want to send.

    If you write 26 bytes to the FIFO, set PKTLEN = 26 and make sure PKTCTRL0 = 0x04.

    Siri

  • Yes you are right. 0x05 is Variable packet length mode.I was wrong but ı change the code : 

    1)      I made the changes 

    0x04,   // PKTCTRL0  Packet automation control.

    0x1A    // PKTLEN    Packet length (in decimal 26)

    2)      I delete the sending size of buffer 

    void cc1101_send_packet(uint8_t* txBuffer, uint8_t size)
    {

    SpiCStrobe(CCxxx0_SIDLE);

    // SPiCWriteReg(CCxxx0_TXFIFO, size);     ***************************
    SpiCWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size);

    SpiCStrobe(CCxxx0_STX);
    }

    3)      Result;

    1. sending data:uint8_t packet[26] = {0x43, 0x43, 0x31, 0x31, 0x30, 0x31, 0x20, 0x74, 0x61, 0x6d, 0x61, 0x6d, 0x6c, 0x61, 0x6e, 0x64, 0x69, 0x20, 0x59, 0x45, 0x53, 0x53, 0x53, 0x21, 0x21, 0x21};

    1.receive data: 1A 43 43 31 31 30 31 20 74 61 6D 61 6D 6C 61 6E 64 69 20 59 45 53 53 53 21 21

    NOTE: as you see first byte 1A means in decimal 26 so it still send the old data because i did not send the size. i have no idea about how this happened?

    2.sending data: fener[26]   = {0x66, 0x65, 0x6e, 0x65, 0x72, 0x62, 0x61, 0x68, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x6b, 0x20, 0x79, 0x61, 0x73, 0x61, 0x20, 0x6f, 0x6f, 0x6f, 0x6c, 0x65, 0x79};

    2.receive data:  66 43 43 31 31 30 31 20 74 61 6D 61 6D 6C 61 6E 64 69 20 59 45 53 53 53 21 21 

    NOTE:As you see just change the first byte. first byte is true but the rest of the buffer are old information. 

    4) But when i use SPiCWriteReg(CCxxx0_TXFIFO, size); (mean send the size of buffer) every message goes true. But ı dont want to send length of buffer

  • Yes you are right. 0x05 is Variable packet length mode.I was wrong but ı change the code : 

    1)      I made the changes 

    0x04,   // PKTCTRL0  Packet automation control.

    0x1A    // PKTLEN    Packet length (in decimal 26)

    2)      I delete the sending size of buffer 

    void cc1101_send_packet(uint8_t* txBuffer, uint8_t size)
    {

    SpiCStrobe(CCxxx0_SIDLE);

    // SPiCWriteReg(CCxxx0_TXFIFO, size);     ***************************
    SpiCWriteBurstReg(CCxxx0_TXFIFO, txBuffer, size);

    SpiCStrobe(CCxxx0_STX);
    }

    3)      Result;

    1. sending data:uint8_t packet[26] = {0x43, 0x43, 0x31, 0x31, 0x30, 0x31, 0x20, 0x74, 0x61, 0x6d, 0x61, 0x6d, 0x6c, 0x61, 0x6e, 0x64, 0x69, 0x20, 0x59, 0x45, 0x53, 0x53, 0x53, 0x21, 0x21, 0x21};

    1.receive data: 1A 43 43 31 31 30 31 20 74 61 6D 61 6D 6C 61 6E 64 69 20 59 45 53 53 53 21 21

    NOTE: as you see first byte 1A means in decimal 26 so it still send the old data because i did not send the size. i have no idea about how this happened?

    2.sending data: fener[26]   = {0x66, 0x65, 0x6e, 0x65, 0x72, 0x62, 0x61, 0x68, 0x63, 0x65, 0x20, 0x63, 0x6f, 0x6b, 0x20, 0x79, 0x61, 0x73, 0x61, 0x20, 0x6f, 0x6f, 0x6f, 0x6c, 0x65, 0x79};

    2.receive data:  66 43 43 31 31 30 31 20 74 61 6D 61 6D 6C 61 6E 64 69 20 59 45 53 53 53 21 21 

    NOTE:As you see just change the first byte. first byte is true but the rest of the buffer are old information. 

    4) But when i use SPiCWriteReg(CCxxx0_TXFIFO, size); (mean send the size of buffer) every message goes true. But ı dont want to send length of buffer

  • 1) Can ı read what ı wrote in TXFIFO, i mean how can I read TXFIFO.

    2) how can ı clear TXFIFO. is there any command for this

  • 1) You cannot read the TXFIFO. After you write to it, you can read the status register TXBYTES, to see how many bytes are in the FIFO.

    2) The FIFO can be cleared by flushing it.

    In your code try to:

    Flush the TX FIFO (SFTX)

    Write your packet to the TXFIFO (26 bytes)

    Strobe STX

    On the RX side:

    Flush RX FIFO (SFRX)

    Strobe SRX

    Wait for packet to be received

    Read the packet (There should now be 28 bytes in your RX FIFO, 29 payload bytes and 2 status bytes).

    Make sure that both the transmitter and receiver are configured for fixed packet length mode and that the packet length is set to 26.

    Siri