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
  • I have finally read the data.

    DS1337 Get Time. twi_i2c_read_err 0, 0 ,[00]

    0 = 0x38
    1 = 0x42
    2 = 0x3A
    3 = 0x88
    4 = 0x23
    5 = 0x47
    6 = 0x17
    7 = 0x70
    8 = 0x7E
    9 = 0xF7
    10 = 0xE9
    11 = 0x23
    12 = 0xC1
    13 = 0x78
    14 = 0x67
    15 = 0x37

    The reason I could not read it was because I read sda scl using only battery power. I can read the data after connecting 3.2v power to VCC, GND in DS1307.

    Thank you for your response. I would appreciate it if you could give me a place to refer to how to convert from buffer data to date and time data.

Reply
  • I have finally read the data.

    DS1337 Get Time. twi_i2c_read_err 0, 0 ,[00]

    0 = 0x38
    1 = 0x42
    2 = 0x3A
    3 = 0x88
    4 = 0x23
    5 = 0x47
    6 = 0x17
    7 = 0x70
    8 = 0x7E
    9 = 0xF7
    10 = 0xE9
    11 = 0x23
    12 = 0xC1
    13 = 0x78
    14 = 0x67
    15 = 0x37

    The reason I could not read it was because I read sda scl using only battery power. I can read the data after connecting 3.2v power to VCC, GND in DS1307.

    Thank you for your response. I would appreciate it if you could give me a place to refer to how to convert from buffer data to date and time data.

Children
Related