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

Problem in twi/i2c communication receiving data

Hi
I'm trying to communicate between nrf51-DK and arduino using twi. I was able to send data from nrf51-DK to arduino using nrf_drv_twi_tx but when I'm trying to send the data from arduino to DK, I'm unable to receive the data. Debugging on arduino side, I'm able to see that the data is being requested on the twi bus and arduino is sending it, but that data is not being displayed on DK side. I'm using the following code to receive the data.

uint32_t err_code;
nrf_drv_twi_config_t p_twi_config = NRF_DRV_TWI_DEFAULT_CONFIG(1);

err_code = nrf_drv_twi_init(&p_twi, &p_twi_config, twi_event_handler);
APP_ERROR_CHECK(err_code);

nrf_drv_twi_enable(&p_twi);

uint8_t tx_data[1] = {0x0D};
uint8_t* rx_data;
while(1)
{    
	err_code = nrf_drv_twi_rx(&p_twi, 0x08, rx_data, 1, false);
	APP_ERROR_CHECK(err_code);
	
	SEGGER_RTT_printf(0, "rx_data is %x\r\n", rx_data[0]);
}

While debugging in Keil on DK side, I can see that EVENTS_RXDREADY is being set but there is no option to see the RXD buffer in the Keil debug window.


One odd thing is that I am using TI's TM75 temp sensor which uses twi and I'm able to read and write without any problem whereas in case of arduino i'm receiving only 0. Also I've tried different pullups with no success. Where can I see the RXD buffer in Keil debug window? How can I view the err_code variale, debug window says "not in scope"? Also any ideas what I might be doing wrong.


Here is the arduino code for reference
bool state = 0;
#include <Wire.h>

void setup()
{
Serial.begin(9600);
Wire.begin(0x08);                // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
pinMode(8, OUTPUT);
}

void loop()
{
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
  Wire.write("abcd"); // respond with message of 6 bytes
  digitalWrite(8, state);
  state = !state;
  // as expected by master
}

For those who don't know what arduino is, it is a board based on atmega328, this code is given as an example code with twi library, so I' think that the code should be working without fail.


Parents Reply Children
No Data
Related