Hi.
I'm trying to use nRF52 as TWI slave.
So far done:
-
Enabled TWIS0 from nrf_drv_cfg.h
/* TWIS */ #define TWIS0_ENABLED 1 #if (TWIS0_ENABLED == 1) #define TWIS0_CONFIG_ADDR0 0x74 #define TWIS0_CONFIG_ADDR1 0 /* 0: Disabled */ #define TWIS0_CONFIG_SCL 0 #define TWIS0_CONFIG_SDA 1 #define TWIS0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH #define TWIS0_INSTANCE_INDEX 0 #endif
-
I get the instance
static const nrf_drv_twis_t m_twis = NRF_DRV_TWIS_INSTANCE(TWIS0_INSTANCE_INDEX);
-
Do the initalization before the master does the first call:
const nrf_drv_twis_config_t config = { .addr = {TWIS0_CONFIG_ADDR0, 0}, .scl = TWIS0_CONFIG_SCL, .sda = TWIS0_CONFIG_SDA, .interrupt_priority = TWIS0_CONFIG_IRQ_PRIORITY }; if(NRF_SUCCESS != nrf_drv_twis_init(&m_twis, &config, twis_event_handler)) { NRF_LOG_PRINTF("twis init failed!\n\r"); } else { NRF_LOG_PRINTF("twis init OK!\n\r"); } nrf_drv_twis_enable(&m_twis);
-
I've also got the event handler ready to go.
void twis_event_handler(nrf_drv_twis_evt_t const * const p_event){ NRF_LOG_PRINTF("twis_evt: %d\n\r",p_event->type); switch(p_event->type) { case TWIS_EVT_READ_REQ: if(p_event->data.buf_req) { (void)nrf_drv_twis_tx_prepare(&m_twis, m_tx_buf, strlen(m_tx_buf)); } break; case TWIS_EVT_READ_DONE: memset(m_tx_buf, 0x00, sizeof(m_tx_buf)); break; case TWIS_EVT_WRITE_REQ: if(p_event->data.buf_req) { (void)nrf_drv_twis_rx_prepare(&m_twis, m_rx_buf, sizeof(m_rx_buf)); } break; case TWIS_EVT_WRITE_DONE: parse_resp(p_event->data.rx_amount); break; case TWIS_EVT_READ_ERROR: case TWIS_EVT_WRITE_ERROR: case TWIS_EVT_GENERAL_ERROR: // m_error_flag = true; break; default: break; } }
However when then master does the first call with the device address, there's nack on the line.
The device address seems OK on the bus 0xE8 (0x74 << 1)and the read bit of the address is ok. We are using 400k clock, however the 100k doesn't seem to do any good either.