This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Talking to an EEPROM via TWI using the NRF51DK

I'm trying to use the NRF51DK to talk to this EEPROM (www.st.com/.../CD00290537.pdf). I've started by trying to modify the twi sensor example. One of the things that's different from the example code with the accelerometer is that this EEPROM requires 3 bytes of data to be sent when you want to write to a specific location (2 byte data_address and 1 byte of data). On the accelerometer, it seems you write 1 byte at a time.

I was able to get the NRF51DK to output coherent I2C information (verified using an o-scope) when sending just 8 bits at a time, but when I tried to increase the size of the message to accommodate 3 bytes, I can't seem to get it to output anymore.

I've attached my modified code (just as a test to get things working, I'm trying to write 0xAA to address 0x0080 on the EEPROM). Basically the only change I've made is to try to increase to size of the data to uint32. I realize this is a byte bigger than I need, but once I get this working, I figured I could cut it back down to 3 bytes.

Anyone have any thoughts? I'm very new to I2C and EEPROMs so I imagine I've violated some rule here.

Thanks!

main.c nrf_drv_twi.c nrf_drv_twi.h

Parents
  • nrf_drv_twi_tx(..) needs and array of bytes/uint8_t not a uint32_t. With your code it will just send out 0 (the lowest 8 bits of the variable). Change to:

    static uint8_t outgoing data[3] = {0x00, 0x80, 0xAA};
    
    err_code = nrf_drv_twi_tx(&twi_driver, M24M02_ADDR, outgoing_data, sizeof(outgoing_data), false);
    APP_ERROR_CHECK(err_code);
    

    0x00 and 0x80 may need to be switched depending if the device needs MSB or LSB first. The array needs to be static or decleared outside of main() to not be placed on the stack (placed in RAM -> not removed after it is used). The last parameter needs to be false if you are not going to do a repeated transfer (tx + rx without issuing a stop condition in between).

  • @olba , i don't find any where a working makefile that has twi and soft device enabled. can you direct me to a working makefile that has twi and softdvice together ? thanks

Reply Children
No Data
Related