cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to register I2C Slave of STM32F4 Board in Variscite Board

Jennifer Liu
Associate
Posted on October 25, 2017 at 20:39

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, 

https://github.com/fboris/STM32Cube_FW_F4/tree/master/Projects/STM32F401-Discovery/Examples/I2C/I2C_TwoBoards_ComIT

 

I modified to address to be 0x30 in this line, (&sharpdefine I2C_ADDRESS        0xA2), and I commented &sharpdefine 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? 

0690X00000608XdQAI.png

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!

#i2c-slave #stm32f4
0 REPLIES 0