Hi.
I'm trying to use nrf52832 twis as twi slave. nrf52 DK(pca10040) is TWI slave (data receiver) arduino uno is TWI master (data transfer)
My code. (examples/peripheral/twi_master_with_twis_slave)
//TWIS init
ret_code_t eeprom_simulator_init(void)
{
//EEPROM_SIM_ADDR is 0x51
//SCL - 3, SDA - 4
ret_code_t ret;
const nrf_drv_twis_config_t config =
{
.addr = {EEPROM_SIM_ADDR, 0},
.scl = EEPROM_SIM_SCL_S,
.scl_pull = NRF_GPIO_PIN_PULLUP,
.sda = EEPROM_SIM_SDA_S,
.sda_pull = NRF_GPIO_PIN_PULLUP,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
/* Init TWIS */
ret = nrf_drv_twis_init(&m_twis, &config, twis_event_handler);
if (NRF_SUCCESS != ret)
{
NRF_LOG_INFO("init failed\r\n");
NRF_LOG_FLUSH();
// break;
}
NRF_LOG_INFO("init ok\r\n");
NRF_LOG_FLUSH();
nrf_drv_twis_enable(&m_twis);
}
//TWIS_EVENT_HANDLER
static void twis_event_handler(nrf_drv_twis_evt_t const * const p_event)
{
NRF_LOG_INFO("twis_evt: %d\n\r",p_event->type);
NRF_LOG_FLUSH();
switch (p_event->type)
{
case TWIS_EVT_READ_REQ:
if (p_event->data.buf_req)
{
ees_readBegin();
}
break;
case TWIS_EVT_READ_DONE:
ees_readEnd(p_event->data.tx_amount);
break;
case TWIS_EVT_WRITE_REQ:
if (p_event->data.buf_req)
{
ees_writeBegin();
}
break;
case TWIS_EVT_WRITE_DONE:
ees_writeEnd(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;
}
}
//MAIN
int main(){
ret_code_t err_code;
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
err_code = eeprom_simulator_init();
APP_ERROR_CHECK(err_code);
while(1){
NRF_LOG_INFO("ok\r\n");
NRF_LOG_FLUSH();
nrf_delay_ms(100);
}
}
Arduino uno code (twi master):
void setup() {
Wire.begin(81); // join i2c bus (address optional for master)
}
byte x = 0;
void loop() {
Wire.beginTransmission(81); // transmit to device #81
Wire.write(x); // sends one byte
Wire.endTransmission(); // stop transmitting
x++;
delay(10000);
}
NRF_LOG_INFO("twis_evt: %d\n\r",p_event->type);
result is '3' (What do you mean?)
and nrf52 DK stop..
what can I do?
Sorry, I'm not good at English myself.