AnsweredAssumed Answered

Unable to register I2C Slave of STM32F4 Board in Variscite Board

Question asked by Jennifer Liu on Oct 25, 2017

I am trying to establish an I2C Connection between the two boards, but the slave (being STM32F4) is not being acknowledged by the Variscite Board. 

 

Desired setup:

- Variscite DART-6UL as the master

- STM32F4 as the the slave. 

 

The Variscite master is set up properly. When I try to read a byte from my slave with the command i2cget 0 0x0A 0x00, I get "Error: using read byte". 

 

I think my set up is right, for the varisite board the I2C1 J11 (Pin 5 SCL line) is connected to PB6 of STM32, and the I2C1 J11 (Pin 7 SDA Line) is connected to PB9 STM32F4.

 

My code is primarily based on the STM32CubeMX I2C Sample Code. This one, STM32Cube_FW_F4/Projects/STM32F401-Discovery/Examples/I2C/I2C_TwoBoards_ComIT at master · fboris/STM32Cube_FW_F4 · GitHu… 

 

I modified to address to be 0x30 in this line, (#define I2C_ADDRESS        0xA2), and I commented #define MASTER_BOARD since I want this board to be the slave. 

 

So I then tried to see if any Chip Addreses are registered. I checked this with the command, i2cdetect 0, the result is an empty matrix. 

 

      0 1 2 3 4 5 6 7 8 9 a b c d e f
00:           -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

 

So this tells me that my master (Variscite) board is not detecting my master. I also tried sampling my transmitted data with Salae Logic Analyzer. Based on the image below, its writing to the wrong address, it writes to 0x14 [NAK], but I specified 0x00 for my data address and 0x0A as my chip address, so why is it writing to 0x14? 

 

 

So again, slave is not being acknowledged. But I have no idea how to get the slave to acknowledge.

 

Update

 

I believe my problem is that Slave is not able to receive properly. The data is actually sending to the correct address 0x14 (I forgot that I had to shift it to the right 1 because of the R/W ACK bit). I used HAL_I2C_Slave_Receive 

 

/* Buffer used for reception */
unsigned char aRxBuffer[1] = { 0x05 };

 

/* The board receives the message and sends it back */
/*##-2- Put I2C peripheral in reception process ############################*/
if(HAL_I2C_Slave_Receive(&I2cHandle, aRxBuffer, 1, 1000) != HAL_OK)
{
      Error_Handler();  
}

 

When I step through this function, it is getting stuck on this line. Thus, returning a timeout. It is actually returning TIMEOUT because I2C_FLAG_ADDR is always SET, but at some point it should RESET, but why is it not doing that? 

 

/* Wait until ADDR flag is set */
if(I2C_WaitOnFlagUntilTimeout(hi2c, I2C_FLAG_ADDR, RESET, Timeout, tickstart) != HAL_OK)
{
    return HAL_TIMEOUT;
}

 

The other issue I have found is that the DR, SR1, SR2 are all set to 0 even after master sends something. So based on my debugging result, I think what I am not understanding is when Master sends a message, how does the slave know what the message is? It cannot be aRxBuffer since I am the one setting that, so it must be coming from DR, but why is that 0? 

 

Thank you, 

I would seriously appreciate the help, I have been stuck on this for 2 weeks now!

Outcomes