2013-06-29 05:22 AM
Hi there,
I got stuck on communicating with a PCF.. I know that i have the address right, because i connected the chip to my Arduino for testing. The program gets stuck onwhile(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)); Here is the codeGPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStruct);
// Connect I2C1 pins to AF
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_I2C1);
// SCL
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_I2C1);
// SDA
// configure I2C1
I2C_DeInit(I2C1);
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_Init(I2C1, &I2C_InitStruct);
// enable I2C1
I2C_Cmd(I2C1, ENABLE);
while
(1)
{
while
(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
//Send I2C1 START condition
I2C_GenerateSTART(I2C1, ENABLE);
//Test on I2C1 EV5 and clear it
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
//Send slave Address for write
I2C_Send7bitAddress(I2C1, 0x20, I2C_Direction_Transmitter);
//Test on I2C1 EV6 and clear it
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
//Send I2C1 slave register address
I2C_SendData(I2C1, 0xFF);
//Test on I2C1 EV8_2 and clear it
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
//Send I2C1 STOP Condition
I2C_GenerateSTOP(I2C1, ENABLE);
I wrote this code for testing and i wanted to get all bits high by sending 0xFF
Am I doing something terribly wrong here?
Any help would be reallyappreciated
#stm32f4-i2c-pcf8574
2013-06-29 06:04 AM
I'd wager you need to be using the address 0x40 not 0x20, the 7-bit addressing complicates things because some systems shift the address, whilst some do not. The ST implementation passes through the address and masks/sets the low order bit.
2013-06-29 06:11 AM
Clive1 that's absolutely awesome!!
I am so happy that this is working now!So maybe a dumb question but how do you calculate this?address 0x20 becomes 0x40 but how?2013-06-29 06:21 AM
Thank you, you helped me a lot!