cancel
Showing results for 
Search instead for 
Did you mean: 

I2C communication

joemccarr
Senior
Posted on December 16, 2016 at 03:19

Hello, I am using an F0 nucleo board and i am trying to talk to a RTC on an expansion board. I can bit-bang the thing and communicate but would like to use the hardware.  I am not getting a TXIS flag or a TXE flag to go high after the first byte.

I am thinking I am not getting an ack back from the RTC.  How is the reading of the ack done by the master. Looking at

the manual and the block diagrams it seems like it is done behind the scenes because the flow chart doesnt show the

reading of the ack just the setting of the TXIS flag which prompts the next byte into the xmit reg.

Anybody have a clue. I don't.

Thanks♯

#ack #i2c
4 REPLIES 4
Posted on December 16, 2016 at 09:00

In case of master transmitter (including the master transmiiting the address), it simply pulses SCK 9 times, outputting the data onto SDA during the first 8 pulses; releasing SDA and reading in ACK from the slave during the 9th. If there is ACK, TXIS is set; if there is NAK, TXIS is not set but NACKF is set instead.

Using an oscilloscope or a LA is highly recommended when debugging I2C.

A common mistake is to use incorrectly formated slave address (the 7 versus 8 bit version of address). See also

https://community.st.com/0D50X00009XkW1mSAF

JW

joemccarr
Senior
Posted on December 16, 2016 at 14:39

Thanks for responding JW.

So this is master mode and I am transmitting to slave.

NACKF is not getting set. I do not see anything on the LA and I can see from the looking at the TX data reg that the first byte just sits there.

The first byte should be the slave address that gets put into the TX data reg. correct?  Or is that done automatically?

I've been over the manual a bunch of times. Don't know what I am missing here.

Below is the code relating to the I2C

uint8_t TxBuffer[] = {0xD0,0x00,0x32,0x59,0x23,1,0x21,0x12,0x16},BytesSent;

uint32_t NbDataToTransmit_I2c=9;

  SET_BIT(RCC->APB1ENR,RCC_APB1ENR_I2C1EN );   //enable I2C1 clock

 

  /* Configure SCL Pin as : Alternate function, High Speed, Open drain, Pull up */

  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);

  LL_GPIO_SetAFPin_8_15(GPIOB, LL_GPIO_PIN_8, LL_GPIO_AF_1);

  LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH);

  LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_OPENDRAIN);

  LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_8, LL_GPIO_PULL_UP);

   /* Configure SDA Pin as : Alternate function, High Speed, Open drain, Pull up */

  LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_9, LL_GPIO_MODE_ALTERNATE);

  LL_GPIO_SetAFPin_8_15(GPIOB, LL_GPIO_PIN_9, LL_GPIO_AF_1);

  LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_9, LL_GPIO_SPEED_FREQ_HIGH);

  LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_9, LL_GPIO_OUTPUT_OPENDRAIN);

  LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_9, LL_GPIO_PULL_UP);

 

  LL_I2C_Disable(I2C1);

  LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);

  LL_I2C_SetTiming(I2C1, 0x10420f13);     //based on 8MHz HSI, freq=100 KHz

  LL_I2C_HandleTransfer(I2C1, 0x000000d0,LL_I2C_ADDRSLAVE_7BIT, NbDataToTransmit_I2c,  LL_I2C_MODE_SOFTEND, LL_I2C_GENERATE_START_WRITE);

  LL_I2C_Enable(I2C1);

   

  BytesSent=0;

 while((I2C1->ISR & I2C_ISR_TC)==0)                       // Loop until end of transfer received

{

          if ((I2C1->ISR & I2C_ISR_TXE)==1)           //txe not going high,

         {

             LL_I2C_TransmitData8(I2C1, TxBuffer[BytesSent]);        

             BytesSent++;

          }

}//xfer Complete

  // Restart here to set up starting slave address to read from ...
joemccarr
Senior
Posted on December 16, 2016 at 15:38

Ok, found my error. It's in the code above. Ugh.

Posted on March 21, 2017 at 12:44

Hi, i'm having the same problem of not having the SET of the TXIS or TXE flag for the transmission of bits.

What was the problem in your code, if i may ask?

Thx