Hello everyone, I'm severely struggling to perform a simple task. I must be missing a very simple answer and, I hope with your help that I resolve the issue.
I am trying to perform write and read commands to my i2c device. I am using the twi_hw_master.c file to perform some of the low level handling. I have my i2c device hooked up to pins 5 (sda) and 6 (scl). I am relying on the internal pull up resistors within the nrf51 for communication.
At the moment, I am seeing that the i2c device becomes unable to read from the device (possibly locking up). It then performs a hardware reinitialization for the twi device on the nrf51.
If I understand the twi_hw_master file and my i2c device, I believe that I have to call the twi_master_transfer() function twice for a i2c read command.
Once, to write the address+W bit followed by the register address that I want to read (with out a stop bit) and, then A second time to read a byte from the I2c Device (followed by a stop bit).
To make this neat and handle problems during mid messages, I created a class to perform a combination of read and write commands. This way, if I failed during the first or second twi_master_transfer function call, I can repeat the process to get the data that I want.
The problem I am experiencing is that the TWI1->ERROR event is being set every time it performs the i2c read command.
Sorry for the long description, I feel like I've been banging my head on this problem for far too long.
Updated: 9/28/15 - 11:31am As requested, Here is more information.
When I used the new drivers, I was getting stuck in an NRF_BUSY_ERROR loop. It could be how I am implementing the driver. After trying for weeks trying to resolve, it's hard for me to think of the things that I haven't tried. I looked into the sample that you provided. The differences that I saw was that most of my code is c++. Which is fine, I added some extern "C" definitions and, I was able to implement the provided code. I'm still looking into implementing the sample code, so more information on this later.
My slave device is an ITG3701 gyroscope from invensense.
I am using the nrf51 DK. pca10028. I believe its the nrf51822. Upon further inspection, the nrf chip itself reads nrf51422 which I found surprising.
I have the S130 softdevice loaded on the chip, however, I am not using it. I have two different programs that I working developing. One involves me communicating over BLE and, one that just needs to communicate to a pc (USB) via UART. I understand that it may be excessive to load the softdevice but, my code doesn't like to compile (more like link) without the correct linking script.
I'll have to consider the pull up resistors. However, before I started this morning changing my code to the nrf sdk drivers, I remember that I was successful in writing to the device. On a side note, I was able to get the read functionality working intermittently by adding a small delay. I added the delay after writing to the device the register that I want data from and before the i2c read command. I.e. ...
do{
do{
bSuccess = twi_master_transfer(((slaveAddr<<1)&0xfe), message, 1, false);
}while( bSuccess != true );
nrf_delay_us(5);
bSuccess = twi_master_transfer(((slaveAddr<<1)|0x1),data,length,true);
}while( bSuccess != true); //start a read i2c sequence