AnsweredAssumed Answered

STM32F0 & I2C - reading data problem (FLAG RXNE)

Question asked by chan-chan on Sep 26, 2014
Latest reply on Nov 13, 2014 by chan-chan

Hello. I'm trying to run a simple I2C test with my STM32 board and I can't get it to work. I'm using STM32F0 Discovery kit (master) and one slave device (some module) that I want to communicate with via I2C bus. Devices are connected via lines SCL, SDA, GND, Vdd and Reset (active low; raised by master). This is my first time using I2C bus on STM32 kit.

In datasheet of my module it says that after the module is either powered on or reset, the module controller will always send a special 4 byte long msg (kind of  “Hello” packet)  to the host system (implying it is ready to work). So for a quick test of I2C communication I just wanted my master (STM32) to read this »Hello« packet via I2C to see if it's working.

So my general idea (code) was to:
1.) initialize HW (I2C, GPIO, LEDs...). Using internal pull-up resistors in I2C init
2.) write I2C "read" function for reading "Hello" packet sent from slave device
3.) print out "Hello" packet to see if it is correct one


In my "Reading" part of my code I first force restart of the slave device by forcing "reset" pin low. Then I try to read the "Hello" package sent by slave:

I2C_TransferHandling(I2C1, DEVICE_ADDRESS1, Num_of_bytes, I2C_AutoEnd_Mode, I2C_Generate_Start_Read);
// read in Num_of_bytes (data)
    for(Cnt = 0; Cnt < Num_of_bytes; Cnt++)
    {
// wait until the RX register is full
        while(I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET);
          if(Num_of_bytes > 1)
          {
            Data[Cnt] = I2C_ReceiveData(I2C1);
...........

The problem is that the program gets stuck at the point of checking RXNE flag as the flag seems to never get set (always stays reset) and therefore no reading data occurs.

So my questions are:

1.) Should I use external pull-up resistors? Currently I'm only using internal ones, as I read (on some blog) that it should be good enough for simple I2C communication

2.) Is my concept of reading data (sent from I2C slave) correct?

Thanks!


Outcomes