hello. I want use I2C program. so, I used twi_master_using_app_twi example. SDA is output only 1byte(0x21). I need to output a continuous 5byte. Where do I need to modify the part. thank you.
hello. I want use I2C program. so, I used twi_master_using_app_twi example. SDA is output only 1byte(0x21). I need to output a continuous 5byte. Where do I need to modify the part. thank you.
You have a function to send data. Second parameter in this function is 0x40 (it is address of my sensor). Third parameter is a pointer to data array which you want to send, fourth parameter is the length in bytes how much bytes you want to send.
ret_code = nrf_drv_twi_tx(&p_twi_instance, 0x40, &dr, 1, false);
APP_ERROR_CHECK(ret_code); // Check for errors in return value
So to send 5 data bytes to the sensor, you cand have something like this
#define DATA_ARRAY_LEN 5
uint8_t data[DATA_ARRAY_LEN] = {0x22, 0x33, 0xFF, 0x10, 0x3A};
uint8_t dev_address = 0x40;
Then in the main program
int main(void)
{
// .....
ret_code = nrf_drv_twi_tx(&p_twi_instance, dev_address, data, DATA_ARRAY_LEN, false);
APP_ERROR_CHECK(ret_code); // Check for errors in return value
}
Not sure this will compile because it is blind written, but you should get the idea.
thank you for your support. I confirm it.
If it solved your problem, please mark question as answered, so other could find this easier. You can do it by pressing grey circle near to my answer.
I have some problem. const pointer(p_data) because, I still send one byte in twi_sensor example.
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * const p_instance,
uint8_t address,
uint8_t const * p_data,
uint32_t length,
bool xfer_pending)
{
return twi_transfer(p_instance, address,
p_data, length,
xfer_pending, true);
}
so, modified source code from const pointer to array. but build is Not OK.
ret_code_t nrf_drv_twi_tx(nrf_drv_twi_t const * const p_instance,
uint8_t address,
uint8_t p_data[10],
uint32_t length,
bool xfer_pending)
{
return twi_transfer(p_instance, address,
p_data[10], length,
xfer_pending, true);
}
error messgae as below.
..........\components\drivers_nrf\twi_master\nrf_drv_twi.c(683): error: #167: argument of type "uint8_t" is incompatible with parameter of type "uint8_t *"
what's mean?
p_data[10] -> &p_data[10] buile is OK. but I still send one byte.