This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Only Sending 1 Byte

Hi

Hopefully a quick question. I want to send a set of bytes 'shtpData' between to routines but only one byte is being sent:

Sending 'unit8_t *dataPacket' of 5 bytes.

bool sendPacket(uint8_t channelNumber, uint8_t dataLength, uint8_t *dataPacket)
{

	uint8_t shtpData[MAX_PACKET_SIZE];

	shtpData[0] = dataLength & 0xFF;
	shtpData[1] = dataLength >> 8;
	shtpData[2] = channelNumber;
	shtpData[3] = sequenceNumber[channelNumber]++;
	for (uint8_t i = 0; i < dataLength; i++) {shtpData[i+4] = dataPacket[i];}

	ret_code_t err_code = srm_nrfx_twi_tx(shtpData, dataLength + 4);
	if (err_code != NRF_SUCCESS) {return false;}

	return true;

}

Receiver 'pData' is only the first byte.

uint32_t srm_nrfx_twi_tx (uint8_t *pData, uint32_t len)
{

	ret_code_t err_code;

	nrfx_twi_xfer_desc_t xfer_init;
    xfer_init.type = NRFX_TWI_XFER_TX;
    xfer_init.address = BNO080_ADDR_SH2_0;
    xfer_init.primary_length = len;
    xfer_init.p_primary_buf = pData;

    err_code = nrfx_twi_xfer(&m_twi, &xfer_init, 0);
    if(err_code != NRF_SUCCESS){return err_code;}

	return NRF_SUCCESS;
}

Any ideas?

Parents Reply
  • Technically, you can set this to the maximum size of the data type (size_t = unsigned int = uint32_t = 2^32 - 1 = 4294967295), but you will run out of memory long before that. The TWI peripheral that nrfx_twi runs on does only send one byte at a time, the application needs to provide a new pointer for every byte being transferred. The buffer part is only used in software for the driver to handle this for you.

    If you were to use the TWIM peripheral with nrfx_twim, there is a limitation of 65534 bytes for each transfer in nRF52840 (16-bit MAXCNT register), while it is limited to 255 bytes (8-bit MAXCNT register) on nRF52832.

Children
No Data
Related