cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Weird

norcio82
Associate II
Posted on September 24, 2009 at 17:20

I2C Weird

5 REPLIES 5
norcio82
Associate II
Posted on May 17, 2011 at 13:24

Hi,

I've got 13 pcb's with STM32F103C6T6A (low density 32kB Flash), the same ( tested and working ) firmware , the same components. I'm using I2C1 (PB6-SCL, PB7-SDA with pull-up resistors) for communication with external ADC. Everything works fine on 9 boards but on other four there is no I2C1 response at all. I checked SDL line with scope directly on micro nothing there ( mirco is running, GPIO, CAN and other peripherials are working... on all boards).

I was thinking that maybe on low density devices I2C1 is not available on PB6 and PB7 pins. But why its working on other boards with the same micro.

I stuck I don't have other ideas what can cause the problem.

If you have any suggestions please help.

Thank you in advance.

TN

[ This message was edited by: norcio82 on 16-09-2009 18:06 ]

danish
Associate II
Posted on May 17, 2011 at 13:24

The data sheet seems to suggest that low-density devices should have I2C1 on PB6 and PB7.

How easy is it for you to debug the boards which are misbehaving?

I would try to see if the problem is hardware or software.

Are the boards doing everything else that you would expect. or is I2C activity the only sign of life you normally get? Would you expect other signs of life if the I2C part of your software got stuck?

Do you ''pump'' the SCL line at power-up to try to clear the I2C bus in case the peripherals were stuck? What would happen in your code if a peripheral did not respond?

How easy would it be for you to download code that tries to use the pins as GPIO pumping one frequency on one pin and a different frequency on the other?

Suppose for example the SDA pin was not properly soldered on those boards? Did you probe the pcb or the STM32 pin itself?

Hope this helps,

Danish

benedwards19
Associate II
Posted on May 17, 2011 at 13:24

Does the SCL line toggle at all (is there an I2C clock?) Also, what is the state of the SCL and SDA lines - high or low? If one or both are low I would check the pull-up resistor and make sure it is well soldered. It could also be the case that the external ADC you are using is somehow damaged or has a short on its I2C pins.

Generally when some boards work and some do not, it's a hardware problem not a firmware problem. Check all of the connections carefully on the SCL and SDA lines, including the pull-up resistors. Try replacing the pull-up resistors, then the ADC, then the micro.

Good luck,

Ben

norcio82
Associate II
Posted on May 17, 2011 at 13:24

Thank you for advice. I think it was firmware issue , now its working fine but I still does not understand why it wasn't.

I only removed this lines:

//set all pins to analog inputs

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;

 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

 

GPIO_Init(GPIOA, &GPIO_InitStructure);

 

GPIO_Init(GPIOB, &GPIO_InitStructure);

from GPIO configuration and it start working ( Dont know why this code is not affecting other boards)...

See below

void GPIO_Config(void){

GPIO_InitTypeDef GPIO_InitStructure;

/* Configure all unused GPIO port pins in Analog Input mode (floating input

trigger OFF), this will reduce the power consumption and increase the device

immunity against EMI/EMC */

 

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;

 

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

 

GPIO_Init(GPIOA, &GPIO_InitStructure);

 

GPIO_Init(GPIOB, &GPIO_InitStructure);

//MCO , clock output

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(GPIOA, &GPIO_InitStructure);

//LD1

GPIO_InitStructure.GPIO_Pin = LD1_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(LD1_PORT, &GPIO_InitStructure);

/* Configure CAN pin: RX */

GPIO_InitStructure.GPIO_Pin = CAN_RXD_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;

GPIO_Init(CAN_RXD_PORT, &GPIO_InitStructure);

/* Configure CAN pin: TX */

GPIO_InitStructure.GPIO_Pin = CAN_TXD_PIN;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(CAN_TXD_PORT, &GPIO_InitStructure);

//Can reset

GPIO_InitStructure.GPIO_Pin = CAN_RS_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(CAN_RS_PORT, &GPIO_InitStructure);

//I2C clock

GPIO_InitStructure.GPIO_Pin = I2C_SCL_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

GPIO_Init(I2C_SCL_PORT, &GPIO_InitStructure);

//I2C SDA

GPIO_InitStructure.GPIO_Pin = I2C_SDA_PIN;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;

GPIO_Init(I2C_SDA_PORT, &GPIO_InitStructure);

}

tomas23
Associate II
Posted on May 17, 2011 at 13:24

One big warning to your approach - if you set all pins to AIN, do you handle the logical value on them? They shall not stay floating!