/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Primer2 and I2C

Username:     
Password:     
             

Forum

# 1   2010-05-10 07:50:46 Primer2 and I2C

pdrljaca
New member
Registered: 2010-04-19
Posts: 3

Primer2 and I2C

Hello all,

I want to connect a sensor to I2C on the extension board of the Primer2.

I added following to the stm32f10x_conf.h file:

#define _I2C
#define _I2C1
#define _I2C2

then to the MENU_code Application_Ini I added:
#define I2C1_SLAVE_ADDRESS7    0xA0

GPIO_InitTypeDef  GPIO_InitStructure;
  I2C_InitTypeDef  I2C_InitStructure;
   
  /* Configure I2C1 pins: SCL and SDA */
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
 
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  /* I2C configuration */
  I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
  I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
  I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7;
  I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
  I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
  I2C_InitStructure.I2C_ClockSpeed = I2C_Speed;
 
  /* I2C Peripheral Enable */
  I2C_Cmd(I2C1, ENABLE);
  /* Apply I2C configuration after enabling it */
  I2C_Init(I2C1, &I2C_InitStructure);

In the code I add

I2C_GenerateSTART(I2C1, ENABLE);
  /* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); 

  /* Send EEPROM address for write */
  I2C_Send7bitAddress(I2C1, I2C_MS5607_ADDRESS, I2C_Direction_Transmitter);

Basically it is the same as the example provided by ST. When I run it I do not see anything happening on SDA and SCL ports. I also ran it in debug mode and I do not see that I2C1 is on and well defined.

My questions are:
1. Where I am wrong?
2. What does this represent I2C_InitStructure.I2C_OwnAddress1 = I2C1_SLAVE_ADDRESS7; ? I used a lot Atmel and Microchip microcontrollers but this I never saw?

Thank you in advance,

Pred

Offline

 

# 2   2010-05-10 09:24:00 Primer2 and I2C

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: Primer2 and I2C

Yeah. ST has realy buggy I2C compared to any other microcontrollers.

First of all you need to shut down FSMC clock or use pin PB7 for I2C. FSMC is used to update display so it's safe to turn it off while you reading I2C. THERE IS NO OTHER WORKAROUND.

Also ST recomends to use high priority interrupts or shut down all interrupt sources during I2C flag checking. This is due to the fact that flags are reset as soon as certain condition is lost. Raisonance in TestI2C project shut down timer2 because it's used to update MEMS and can interfere with I2C.

My interrupt only version of I2C master didn't work without timer stop. Sorry but no examples - I'm using pure CMSIS (witout ST-LIB) and code is a too big (but fast).

Offline

 

# 3   2010-05-10 13:24:26 Primer2 and I2C

pdrljaca
New member
Registered: 2010-04-19
Posts: 3

Re: Primer2 and I2C

Hello, thank you for your answer.

How do I shut down the FSMC clock from code?

Also what I see when I compile the example is that the I2C1 is operational and in my case that is not true...

My sensor also works with SPI but I wanted to check the I2C since there is nothing connected to those pins?

Best regards,
Pred

Offline

 

# 4   2010-05-10 14:15:46 Primer2 and I2C

pdrljaca
New member
Registered: 2010-04-19
Posts: 3

Re: Primer2 and I2C

For the moment it works, at least hardware of the I2C I can see it enabled.

What helped is I copied complete conf file to my project directory and added two lines I forgot in my init code before the init of the I2C

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
    /* I2C1 Periph clock enable */
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

I thought it will be more easy with circle OS.

Thank you for the pointer and I keep you informed how it will all finish at the end.

Regards,
Pred

Offline

 

Board footer