Hello everyone, I'm actually working on the MCBSTM32E eval board which is composed of the STM32F103ZE. It is connected to a smart battery component (BQ2040 from TI). The bus between them is SMBUS, so I connected the BQ to I2C1. I have some questions about this latter. I can easily communicate with the BQ BUT : - First : my own address is always taken by the soft as a 10-bit one instead of a 7-bit (it means that I have to put 0x03 if I want my I2C address to be 0x01) and it is the same when I want to write something in the BQ whose address is 0x0B I have to put 0x17. It seems that I have to add one extra bit (1). How can I change that ? - Second : the example given in µvision directories (ST Examples) uses while loop to wait for an event (as required in . But when an error occurs (like a missing ack), it means that I'm stuck in the loop forever. How could I handle it ? I think when an error occur I should reset the I2C and recall the function, but I have no idea on how to recall it. - Third : I don't know why but the BQ sends me an Ack even after the Data Byte H while it should send nothing or a Nack which would mean that I can generate my stop. I hope my post is not that confusing cause I tried to make as clear as I can. Thanks in advance, Regards Gary
The format for the 7 bit address varies. It is commonly shown pre-shifted the library writer must have used that convention. The SMBus Protocol Spec is available at SMBus.org . It has some nice diagrams. TI also has some good App Notes
That is a pretty old chip.
Thanks for you answers. Robert I'm sorry if I'm too stupid to hope that a "send7bitAddress" function needs the 7bit address instead of the 8bit shifted to the left. Moreover the example given on the FWLib made me think that there was no need to shift, I was wrong : sorry ! Just want to add that 0x17 works (as whatever the lsb is, it is changed with the I2CDirection). For the Nack I did not know that it was the master's job to do it. So now I disable the ack before stopping the communication and the protocol is respected. To avoid infinite loop, I will figure something out but I just wanted to know if someone did it before. Thank you again, Regards Gary
The Master should Nack and Stop when it is done reading. You know how much data you are getting back 2 bytes for a word. the First byte if it is a block (String)
As far as how the STM32 I2C works, I would look at the STM32 Reference Manual. I have not reason to believe that it is not complete. That along with the STM32 library source code should allow you to do whatever you need to do AND provide at least 1 possible way to do it.
- Third : I don't know why but the BQ sends me an Ack even after the Data Byte H while it should send nothing or a Nack which would mean that I can generate my stop. I hope my post is not that confusing cause I tried to make as clear as I can.
Looking at the data sheet seems to indicate that this is what it is supposed to do. Does your data sheet show something different?
I2C_Send7bitAddress(I2C1, 0x17, I2C_Direction_Transmitter);
does require the address to be shifted left. 0x17 is not valid. What was it that made you think that it did not need to be shifted left 1 bit? The source code for this library is provided and it CLEARLY expects the address to be shifted left 1 bit.
I can not help past this point. If the Libraries do not suit your needs you can code it your self. If the libraries are supported and do not work, check for updates, look at the source code if it is available, or contact the Manufacturer. Sorry I can not help further.
Thank you for your answer but I knew that. The thing is that I use the ST FWLib and so in the function "I2C_Send7bitAddress(I2C1, 0x17, I2C_Direction_Transmitter);" I expected that the address did not need the extra bit as we notify it with the I2C_Direction. It is just that I dont find it really clear. Moreover the function is named Send7bitAddress so it was clear (for me) that we did not have to add the R/W bit. The thing that bothers me most is the loop used to wait for an event. I dont know, even with interrupt, how I can recall the function if an Ack miss happens. Regards
Not an ARM Guy But for I2C (and SMBus) it AAAAAAAW
so the battery is 0x16 b00010110 AKA 0x0B b00001011
So using the Address a 0x0B you may need to shift left one to skip the Read / Write Bit. ( Depending one what the Hardware wants)
View all questions in Keil forum