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

Cannot get 400 kbps TWI_SW frequancy with clock stretching

Hi Nordic developers,

I'm using TWI software driver provided by NORDIC. I need to have 400 kbps frequancy. I have seted TWI_DELAY() to 0 and TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE to 1000. (for clock stretching)

Just checking with osciloscope SCL clock period is 3us instead of 2.5us.

When I set the TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE to 0 I'm getting exactly 2.5 us.

How can I get 2.5 us SCL clock cycle with clock stretching?

I'd be really glad, if someone can help me.

Thanks in advance,

Gor

Parents
  • Hi,

    I've modified a little bit the twi_sw_master.c driver and was able to reach 400kHz with timeout enabled. Instead of using twi_master_wait_while_scl_low() function I'm using the twi_master_wait_while_scl_low() macro shown bellow.

     #define twi_master_wait_while_scl_low()	do{                                             \
        TWI_SCL_HIGH();	                                                                        \
        while(TWI_SCL_READ() == 0 && timeout_counter != TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE)	\
        {								\
            timeout_counter++;		    \
        }						        \
        } while(0)
    

    And in every function were this macro is used I've added

     #if TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE != 0
        uint32_t volatile timeout_counter = 0;
     #endif
    

    Just check with the Oscilloscope I'm getting 2.4us SCL cycle. Please correct me if I'm doing something wrong.

Reply
  • Hi,

    I've modified a little bit the twi_sw_master.c driver and was able to reach 400kHz with timeout enabled. Instead of using twi_master_wait_while_scl_low() function I'm using the twi_master_wait_while_scl_low() macro shown bellow.

     #define twi_master_wait_while_scl_low()	do{                                             \
        TWI_SCL_HIGH();	                                                                        \
        while(TWI_SCL_READ() == 0 && timeout_counter != TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE)	\
        {								\
            timeout_counter++;		    \
        }						        \
        } while(0)
    

    And in every function were this macro is used I've added

     #if TWI_MASTER_TIMEOUT_COUNTER_LOAD_VALUE != 0
        uint32_t volatile timeout_counter = 0;
     #endif
    

    Just check with the Oscilloscope I'm getting 2.4us SCL cycle. Please correct me if I'm doing something wrong.

Children
No Data
Related