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

twi transmission address never shows correctly as i set

my TWI device sensor, both its writing and reading address is 0x55. This seems weird for library of nRF since the last bit should be set as 0 for transmission and 1 for receiving (as below link)

https://devzone.nordicsemi.com/f/nordic-q-a/6431/unusual-twi-i2c-problem

However, that is the configuration of that device and I can't change. According to their document, just send 0x55,0xaa and 0x55, then get data. But for nordic, the data i caught from scope is 0x54,0xaa and 0x55 (0x55 is changed into 0x54 because of transmission)

I would like to know if i can send directly via TWI (dont care about address) 0x55,0xaa and 0x55 and then capture data as their sample code and how

thanks

Parents Reply Children
  • firstly, if take a left shift, it should be 0xaa, right?

    secondly, I checked the sample code provided by Noridc (twi_sensor_pca_10028), the address is shifted right:

    #define MMA7660_ADDR        (0x98U >> 1)

    the last thing, for my sensor, I checked every address which can return me an ACK and only 0x2a (=0x55>>1) is able to do that.

    however, when analyzing using scope, the transmitted data shows :0x54 ( it is 0x54 not 0x55 since it is transmission), but the sensor, which is Chinese product, expect to receive 0x55,0xaa,0x55 and it will return value ( it is chinese so it is not standard).

    Thus,from the functions provided by Nordic :nrf_drv_twi_tx  and nrf_drv_twi_rx,  it is impossible to send via SDA the data as expected 

  • Hi,

    Sorry for the counting error there, I fixed it in the original reply to 0xAA as you say.

    Regarding the define, according to the MMA7660 data sheet the slave address is 0x4C, so the 0x98 value is that slave address shifted to the left.

    What Chinese product is this, do you have the name of a link to the data sheet?

    Regards,
    Terje

  • data sheet below and not available in english

    http://style.winsensor.com/pro_pdf/ZM03.pdf

    their sample code (send directly byte via i2c)

    int main(void)
    {
    u8 time=0,cnt;
    delay_init();
    i2c_init();
    led_init();
    tim3_init(990,719);
    usart_init(9600);

    NVIC_Configuration();

    while(1)
    {

    if(circle_flag_100ms) //周期100ms 采样后处理 更新数据
    {
    circle_flag_100ms=0;
    LED0=!LED0;
    if(cnt>99) { cnt=0; }
    if(time++>4)
    {
    time=0;
    i2c_start(); //主机发送起始信号
    i2c_send_byte(0x55);
    if(!i2c_wait_ack())
    {
    i2c_send_byte(0xAA);
    }

    i2c_start();
    i2c_send_byte(0x55);
    if(!i2c_wait_ack())
    {
    temp=i2c_read_byte(1);//读取
    }
    i2c_stop(); //发送停止信号

    printf("\r\n当前输出值:%d ,包序号: %d\r\n",temp,cnt++);
    }
    }
    }
    }

  • Hi,

    I am sorry. I do not understand Chinese.

    But. You write that you do not care about address. You must use an address in order to transmit and receive over twi. Is 0x55 not the address? You have to figure out what the address is, and use the correct address, for your communication.

    Regards,
    Terje

  • that sensor doesn't comply with I2c ,as far as we reached them and learnt.

    As the sample above you may see, they just send byte 0x55  ( not define that transmit or receive) and 0xaa then 0x55 and got data. For Nordic library, I couldn't do that because of no directly send function.

    Any way, we switched to another sensor and passed that problem, but if possible I still want to know can nordic send directly ?

Related