1 Reply Latest reply on Nov 3, 2020 5:38 AM by AH_96

    i2c communication using HAL


      I'm trying to implement some i2c communication using PSoc6 with ModusToolbox running FreeRTOS.


      There is some documentation, but the Code snippet 3 found here:

      Hardware Abstraction Layer (HAL)


      I think it's incomplete and confusing.


      Why is the handler checking on Slave events? it should be Master:  CYHAL_I2C_MASTER_WR_CMPLT_EVENT


      I need to write a value to a register number or read a value at a register number (address is one byte)... how do I do that?



      the function cyhal_i2c_master_transfer_async(&i2c_master_obj, I2C_SLAVE_ADDRESS, tx_buff, 3, rx_buff, 3); 


      It doesn't show how tx_buff or rx_buff are implemented... can someone give a better example? should I send the address (1 byte) in the tx_buff of what I want to read?? or in the rx_buff? ... Also, how do I setup the Timeout?


        • 1. Re: i2c communication using HAL

          Hello gepa_4776901


          You can refer our I2C master code example for an example on I2C master mode. GitHub link for I2C Master CE. The example shows sending multiple packets to the slave that can be implemented in your case as well. Can you let us know the packet structure that you require?


          To answer your questions,

          1. The address need not be sent with the Tx byte. This is taken care by the firmware itself when you pass the slave address.

          2. The Tx buffer is simply the data that you need to transfer and the Rx buffer is the pointer to the location where the data sent by the slave will be located.

          3. For timeout, you need to use the cyhal_i2c_master_write and cyhal_i2c_master_read APIs that take the timeout as a parameter. You can refer the CE mentioned above that uses these APIs.


          Best regards,