I'm trying to get the TWIM peripheral up and running on a custom board with an NRF52810 running SDK15 and S112.
My board is properly advertising, and publishing our custom service and characteristics.
I have an impossible schedule to meet, and have been bumping my head against the TWIM driver all day. I suspect that I am doing something totally stupid, but can't figure it out...
The TWIM instance initializes and enables without error. It will run through the nrfx_twim_xfer function with no error in non-blocking mode, but the handler never gets called, and the TWIM never starts the driver (verified with scope and TWIM0 register settings. In blocking mode, it just never exits and still nothing comes out the bus. In any case I never get an I2C error, I just get nothing happening.
If I stop the code execution a little after the twim_xfer call (the transaction should have completed long ago) then I will see the following non-zero values in TWIM0:
EVENTS_TXSTARTED 0x00000001 (I assume this means that I requested a transmit event)
SHORTS LASTTX_STOP is Enabled (all others disabled)
INTEN STOPPED and ERROR are enabled (all other disabled)
ENABLE 0x6 ENABLED (my understanding is that this means twim is running with easy dma enabled)
PSEL SCL 0x5, SDA 0x6 (correct pins selected)
FREQUENCY 0x01980000 (This should be 100 kHz)
TXD PTR 0x200032D0 (address of my buffer), MAXCNT 0x2 (correct number of bytes that I am trying to send), AMOUNT 0 (this is my problem!)
ADDRESS 0x78 (correct slave address for the device I am trying to talk to)
Any help would be appreciate. My schedule for production is impossible and I am already behind. Relevant TWI code is below(sorry for calling it I2C in it). The end of i2c_init() is where I am testing the interface. I tried testing elsewhere as well, but moved it here for brevity and convenience.
Thanks,
-F
#define I2C_INSTANCE_ID 0 static bool volatile i2cXferComplete = false; static uint8_t i2cState = I2C_IDLE; static uint8_t i2cPending = 0x00; static const nrfx_twim_t i2c = NRFX_TWIM_INSTANCE(I2C_INSTANCE_ID); void i2c_handler(nrfx_twim_evt_t const *event, void *context) { if(event->type == NRFX_TWIM_EVT_DONE) { i2cXferComplete = true; /* BOGWTF -- ADD PENDING CODE FOR AZOTEQ AND FUEL GAUGE */ } } bool i2c_complete(void) { return i2cXferComplete; } void i2c_set_state(uint8_t state) { i2cState = state; } uint8_t i2c_get_state(void) { return i2cState; } void i2c_init(void) { ret_code_t error; const nrfx_twim_config_t config = { \ .frequency = NRF_TWIM_FREQ_100K, \ .scl = I2C_SCL_PIN, \ .sda = I2C_SDA_PIN, \ .interrupt_priority = APP_IRQ_PRIORITY_HIGH, \ .hold_bus_uninit = false, \ }; uint8_t testData[5] = { 0x4A, 0x07, 0x00, 0x00, 0x00 }; uint8_t testLength = 2; error = nrfx_twim_init(&i2c, &config, i2c_handler, NULL); // error = nrfx_twim_init(&i2c, &config, NULL, NULL); APP_ERROR_CHECK(error); nrfx_twim_enable(&i2c); const nrfx_twim_xfer_desc_t test = NRFX_TWIM_XFER_DESC_TX(I2C_LED_ADDRESS, testData, testLength); error = nrfx_twim_xfer(&i2c, &test, 0); APP_ERROR_CHECK(error); while(1); }