This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Why can not read twi data ? twi interfacing with RTC DS1307....

Why can not read twi data ? at nrf52832 chip.... but Read well in Arduino....

twi interfacing with RTC DS1307....

please give me some hint.....

  1. nrf_drv_config.h

    #define TWI0_ENABLED 1 #define TWI1_ENABLED 1

  2. define

    #define DS1307_I2C_SCL_PIN 9 // 9 #define DS1307_I2C_SDA_PIN 10 // 10

    #define DS1307_ADDR 0x68U //I2C ADDR 0x68U

    void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context) {
    switch(p_event->type) { case NRF_DRV_TWI_EVT_DONE: break; default: break; } }

    void twi_init (void) { ret_code_t err_code;

    const nrf_drv_twi_config_t    twi_ds1307_config = {
    	.scl                    = DS1307_I2C_SCL_PIN,
    	.sda                   = DS1307_I2C_SDA_PIN,
    	.frequency          = NRF_TWI_FREQ_100K,
    	.interrupt_priority = APP_IRQ_PRIORITY_HIGH
    };
    
    err_code = nrf_drv_twi_init(&m_twi_ds1307, &twi_ds1307_config, twi_handler, NULL);  		
    APP_ERROR_CHECK(err_code);
    
    nrf_drv_twi_enable(&m_twi_ds1307);
    

    }

  3. reading.....

    uint8_t r_buf[16]={0,}; err_code = nrf_drv_twi_rx(&m_twi_ds1307, DS1307_ADDR, r_buf, sizeof(r_buf)); APP_ERROR_CHECK(err_code);

    for (uint32_t i = 0; i < 16; i++) { printf("%d = 0x%02X \n",i, r_buf[i] ); }

  4. result

1 = 0x00 2 = 0x00 ... 15 = 0x00

all value zero....

Parents Reply Children
No Data
Related