cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Slave Example

gil23
Associate III
Posted on April 27, 2014 at 19:56

Hi I'

m working on STM32F401 disco EVB with the 

Standard Peripherals Library

,

Where i can find a working example on I2C slave?  

12 REPLIES 12
munger
Associate II
Posted on May 01, 2014 at 20:33

I would also like to see a I2C example from ST Micro. Not one with DMA, not one that is board to board just one that is some type of eval board to a memory device or a ADC or something like that. I've seen some with the STM32Cube but it is so hard to figure out what is going on.

Mike

munger
Associate II
Posted on May 05, 2014 at 03:43

You can download STM32F4xx_DSP_StdPeriph_Lib_V1.3.0 here:

http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/PF257901

Mike

munger
Associate II
Posted on May 05, 2014 at 23:14

Yay! I've got this working pretty well. My biggest problem was that the address of the sensor is x48 and I know it is 7 bit but I did not realize that it needs to be left justified before I call I2C_Send7bitAddress. So, I need to send a x90.

My last remaining problem is that the register I'm reading is 16 bit and I can't quite figure out how to use the std periph library functions to clock in that second byte. I don't need to send the bus address again or the register address, just need to clock in 8 more bits.

Code looks like this after it gets the high byte.

  /* Receive high byte of Data */

  data_high = I2C_ReceiveData(I2C1);

 

// Read low byte of Data

  /* Prepare an NACK for the next data received */

  I2C_AcknowledgeConfig(I2C1, DISABLE);  

 

  /* Test on I2C1 EV7 and clear it */

  timeout = ADT7410_TIMEOUT_MAX; /* Initialize timeout value */

  while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_RECEIVED))

  {

    /* If the timeout delay is exeeded, exit with error code */

if ((timeout--) == 0) 

{

return ERROR;

}

  }

 

  /* Receive the Data */

  data_low = I2C_ReceiveData(I2C1);

// Build 16 bit data word

*read_data = (uint16_t) data_high;

*read_data <<= 8;

*read_data += (uint16_t) data_low;

  I2C_GenerateSTOP(I2C1, ENABLE);

  /* return the read data */

  return SUCCESS;

but it times out and I don't see that second transfer on the scope so I must not be calling I2C_CheckEvent correctly or something like that.

I'd appreciate any ideas.

Mike