2013-12-19 11:56 PM
Hello everybody,
I have a problem with the I2C protocol used by the STM32F0.
In fact, after setting up all the necessary stuff if I use this code:
I2C_GenerateSTART(I2C1);
I get the waveform I2C_ONE
http://www.coocox.org/forum/images/ckeditorimages/20131219181541_I2C_ONE.png
The first channel is SDA and the second one is SCL.
Otherwise if I use this code:
I2C1->CR2=0xAA;
I2C_GenerateSTART(I2C1);
I get the waveform I2C_TWO.
http://www.coocox.org/forum/images/ckeditorimages/20131219181602_I2C_TWO.png
In any case, if I use I2C_SendData(....
I am not able to get any data on the I2C bus.
Can you try to use the I2C protocol with the STM32F0 and give me a feedback?
Thanks a lot,
Peppe
stm32f0-i2c-start2013-12-20 03:30 AM
Hi.
This is a working test code for 7 bits addressing. Use init, and next send address your slave and length of data. void I2C_PCF_init() { RCC->AHBENR|=RCC_AHBENR_GPIOBEN; GPIOB->MODER|= GPIO_MODER_MODER6_1|GPIO_MODER_MODER7_1; GPIOB->OSPEEDR|=GPIO_OSPEEDER_OSPEEDR6|GPIO_OSPEEDER_OSPEEDR7;//predkosc 50MHZ GPIOB->AFR[0]|=0x11000000; //AF1 RCC->APB1ENR|=RCC_APB1ENR_I2C1EN ; //enable clock for I2C1 I2C1->CR1|=I2C_CR1_PE; //set PE I2C1->CR1&=~I2C_CR1_PE; //reset PE while(I2C1->CR1&I2C_CR1_PE); //while PE ==1 I2C1->TIMINGR|=(PRESC << 28)|(SCLL<<0)|(SCLH<<8)|(SCLDEL<<20)|(SDADEL<<16); //configure for 48Mhz clock I2C1->CR1|=I2C_CR1_PE; //set PE } void I2C_PCF_send(int address, int length) { while ((I2C1->ISR & I2C_ISR_TXE)==0); //while TXE ==0, buffer is full I2C1->CR2|=(address<<0)|(length<<16)| I2C_CR2_AUTOEND ; //address SLAVE 7bits I2C1->CR2 &=~ I2C_CR2_RD_WRN; //write I2C1->CR2 |= I2C_CR2_START; while ((I2C1->ISR & I2C_ISR_TXE)==0); //while TXE ==0, buffer is full I2C1->TXDR=0xff;//example data }2014-01-07 07:38 AM
Hi h.n,
I'll use it soon and I'll inform you :) Thanks a lot in advance for your help. Ciao :)2014-01-08 06:18 AM
Hi hn,n
thanks a lot for your code. It's working... finally! Now, pease, can you help me on set up the I2C2 on STM32F051R8 uC? I am able to set up the I2C1 but not able to set up the I2C2... it seems it has a different clock activation...2014-01-14 09:56 AM
Hi,
here my update: if I try to communicate with IC2 of STM32F4 discovery it acks the address while, if I send the I2C2 address of the stm32F0 discovery, while if I try to send an address rom I2C1 of stm32f0 I am not able to see any ack. How can I set the slave of I2C2 of STM32F0?2014-01-15 03:16 AM
Hi
It is not clear what you are trying to do : ''here my update: if I try to communicate with IC2 of STM32F4 discovery it acks the address'' '' while, if I send the I2C2 address of the stm32F0 discovery, '' So you have set up the I2C 2 - who is sending the I2C 2 address? ''while if I try to send an address rom I2C1 of stm32f0 I am not able to see any ack.'' Who is sending the I2C 1 address ''How can I set the slave of I2C2 of STM32F0?'' The I2C peripheral must be configured as a I2C slave. The example code probably configures the I2C peripheral as a master. What is connected to what? Are all 3 on the I2C bus? What are you using for he pull ups?2014-01-15 05:28 AM
Ok,
now I try to be clearer and I try to semplificate all. Here what I am doing: STM32F0 discovery: I use I2C1 module like I2C master. STM32F0 discovery: I use I2C2 module like I2C slave. Pull-up resistor 4k7 I2C1 sends the slave address (I2C2 address) to I2C2 module. I am not able to see any ack during the 9th clk. Do you know how to set up the I2C2 module as slave? PS: I tried to do the same thing uging I2C1 of stm32F0discovery and I2C2 module of STM32F4discovery but no good resuts at all...2014-01-15 05:40 AM
Have you considered that you might have set the slave address incorrectly ?
Could it be you ''overdrive'' your slave, i.e. clocking too fast ? Did you measure those waveforms on the pins of your I2C slave ?2014-01-15 07:05 AM
Hi
Very basic question - Have you connected I2C1 pins (SDA & SCL) and I2C2 pins together on the same I2C Bus?2014-01-16 02:41 PM
Hi,
I connected SDA of IC1 with SDA of IC2SCL of IC1 with SCL of IC2I am sure I did set correctly the slave address of IC2 because I set it in init() function...