1

I'm using the HAL libraries to program my STM32f103RBT6 board to interface with the Aardvark's I2C/SPI host adaptor. I'm currently using the I2C stack and I have written the following code to compare the data that I have sent and what I have received:

/*Some code written to initialize all the things required by the protocol, handled by the STM32CubeIDE.*/    
        
/* User code begins here*/
    HAL_StatusTypeDef status = HAL_OK;    /* Status to check if API call is HAL_OK or HAL_ERROR*/
    uint8_t tx_buff[5]={0x01,0x02,0x03,0x04,0x05}; /* The TX buffer with size 5*/
    uint8_t rx_buff[5]={0};                        /* The RX buffer with size 5*/
    char result[5];              /* string to express whether my test failed to passed*/
    int flag;            /* flag used to store result of comparison between TX and RX buffer*/
             
    if (status == HAL_OK)
       {
       status = HAL_I2C_Master_Transmit(&hi2c1, (0x24<<1) | 0, &tx_buff[0], 5, HAL_MAX_DELAY);
       }
        
    if (status == HAL_OK)
       {
         status = HAL_I2C_Master_Receive(&hi2c1, (0x24<<1) | 1, &rx_buff[0], 5, HAL_MAX_DELAY); 
       }
       
    flag = memcmp(&tx_buff, &rx_buff, 5);
          
    if (flag == 0 && status == HAL_OK)
       {
         strcpy(result, "PASS");
       }
            
    else 
       {
         strcpy(result, "FAIL");
       }
        
    while (1)
       {


           HAL_Delay(10);
       }
    
/* User code ends here*/
           

The output on my Aardvark GUI app is: Transaction Log

The problem is that I'm sending the data once and then receiving it once. The problem is that you can see in the transaction log the write and read operation is being carried out multiple times.

I would appreciate if someone helps me out in this regard.

Yours truly,
Wajahat Riaz
Electrical Engineer

0 Answers0