cancel
Showing results for 
Search instead for 
Did you mean: 

I2C START and master mode

julien
Associate II
Posted on April 23, 2008 at 06:06

I2C START and master mode

8 REPLIES 8
julien
Associate II
Posted on May 17, 2011 at 12:31

Hello,

I'm using the USART1 and after the instruction to generate start

I2C_GenerateSTART(I2C1, ENABLE);

the I2C1 master mode seem not to be selected

the program stop at this instruction

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

----

#define ClockSpeed 400000

----

....

....

/* GPIO configuration ------------------------------------------------------*/

/* Configure I2C1 pins: SCL and SDA ----------------------------------------*/

GPIO_InitStructure_i2c.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;

GPIO_InitStructure_i2c.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure_i2c.GPIO_Mode = GPIO_Mode_AF_OD;

GPIO_Init(GPIOB, &GPIO_InitStructure_i2c);

/* Enable I2C1 ----------------------------------------------------*/

I2C_Cmd(I2C1, ENABLE);

/* I2C1 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 = ClockSpeed;

I2C_Init(I2C1, &I2C_InitStructure);

/*----- First transmission Phase -----*/

/* Send I2C1 START condition */

I2C_GenerateSTART(I2C1, ENABLE);

/* Test on I2C1 EV5 and clear it */

while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));

Thanks..

lanchon
Associate III
Posted on May 17, 2011 at 12:31

you're not showing where you enable the clock to the macrocell.

I init like this:

I2C_DeInit(i2c);

I2C_InitTypeDef i =

{

I2C_Mode_I2C,

I2C_DutyCycle_2,

0,

I2C_Ack_Enable,

I2C_AcknowledgedAddress_7bit,

clock

};

I2C_Init(i2c, &i);

(no I2C_Cmd() call since it's embedded in I2C_Init())

then I do this:

I2C_GenerateSTART(i2cInterface.getI2C(), ENABLE); // send start when bus becomes available

i2cInterface.waitForEvent(I2C_FLAG_SB);

julien
Associate II
Posted on May 17, 2011 at 12:31

in order to use the i2c in master mode it is enough to generate a start with the function I2C_GenerateSTART(I2C1, ENABLE); ?

thanks

julien
Associate II
Posted on May 17, 2011 at 12:31

My clock configuration

----

RCC configuration :

void RCC_Configuration(void)

{

/* RCC system reset(for debug purpose) */

RCC_DeInit();

/* Enable HSE */

RCC_HSEConfig(RCC_HSE_ON);

/* Wait till HSE is ready */

HSEStartUpStatus = RCC_WaitForHSEStartUp();

if(HSEStartUpStatus == SUCCESS)

{

/* Enable Prefetch Buffer */

FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

/* Flash 2 wait state */

FLASH_SetLatency(FLASH_Latency_2);

/* HCLK = SYSCLK */

RCC_HCLKConfig(RCC_SYSCLK_Div1);

/* PCLK2 = HCLK */

RCC_PCLK2Config(RCC_HCLK_Div1);

/* PCLK1 = HCLK/2 */

RCC_PCLK1Config(RCC_HCLK_Div2);

/* PLLCLK = 12MHz * 6 = 72 MHz */

RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_6);

/* Enable PLL */

RCC_PLLCmd(ENABLE);

/* Wait till PLL is ready */

while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

{

}

/* Select PLL as system clock source */

RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

/* Wait till PLL is used as system clock source */

while(RCC_GetSYSCLKSource() != 0x08)

{

}

}

/* Enable GPIOA and AFIO clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);

/* Enable USART1 clocks */

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/* Enable I2C1 clocks */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);

}

julien
Associate II
Posted on May 17, 2011 at 12:31

wich library do you use, I haven't functions getI2C() or waitForEvent() I'm using the um0427 library

lanchon
Associate III
Posted on May 17, 2011 at 12:31

hi,

you're not enabling clock to GPIOB. the resynchronization of the input pins is not working since the synchronizer gets no clock, so the input signals to the I2C macrocell are constant values. if they are constant low values, then the I2C will think that the bus is in use and wait forever for it to become free before sending the start event. that's probably what's happening.

> wich library do you use

not really a library:

http://www.st.com/mcu/forums-cat-6552-23.html

http://www.st.com/mcu/forums-cat-6701-23.html

> it is enough to generate a start with the function I2C_GenerateSTART(I2C1, ENABLE); ?

yes.

16-32micros
Associate III
Posted on May 17, 2011 at 12:31

Hi lanchon,

You are online :) Cheers,

STOne-32.

julien
Associate II
Posted on May 17, 2011 at 12:31

Thank you Lanchon,

It is necessary that I pay more attention,

I'm student in a traning period...

Thank you for reply..