żabek
Newbie level 3
- Joined
- Nov 20, 2012
- Messages
- 3
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,308
Hello
I'm facing a strange problem and I cannot find a solution myself, I'm simply stuck.
I'm trying to interface STM32F107 microcontroller with (among others) 2 PCF8574 I2C bus expanders. Hardware seems to be OK, verified with oscilloscope, seems correct. Unfortunately neither of PCFs change output states as desired. Below I attach my code, maybe there's something that causes malfunction and I cannot see it.
I don't want to use ST's library. Code isn't interrupt driven.
Sorry for comments in Polish ;-)
Below how the transmission is called from main function
Addresses are OK, chips send ACKs when they're supposed to but do not change output states. Sometimes I succeed when I'm performing step-by-step debugging...
Could anyone have a look and help me find a solution, please?
BRegards
Damian
I'm facing a strange problem and I cannot find a solution myself, I'm simply stuck.
I'm trying to interface STM32F107 microcontroller with (among others) 2 PCF8574 I2C bus expanders. Hardware seems to be OK, verified with oscilloscope, seems correct. Unfortunately neither of PCFs change output states as desired. Below I attach my code, maybe there's something that causes malfunction and I cannot see it.
I don't want to use ST's library. Code isn't interrupt driven.
Code:
void I2CInit(void)
{
RCC->APB1ENR |= RCC_APB1Periph_I2C1; //wlacz zegar dla I2C1
GPIOB->CRH |= 0x00000000;
GPIOB->CRL |= 0xFF000000;
I2C1->CR2 |= 0x36; //36MHz
I2C1->TRISE = 0x26; //1us
I2C1->CCR = 0xB4; //100kHz
I2C1->CR1 = 0x01; //wlacz I2C
}
void I2CStart(void)
{
uint16_t dummy;
while((((I2C1->SR2) >> 1)&0x01)!=0x00); //czekaj poki BUSY
I2C1->CR1 |= (uint16_t)(0x01 << 8);
while((((I2C1->SR1) >> 0)&0x01)!=0x01); //czekaj az ustawi sie flaga SB
dummy = I2C1->SR1;
dummy = I2C1->SR2; //skasuj ewentualne flagi
}
void I2CAddr(uint8_t address)
{
uint16_t dummy;
I2C1->DR = address;
while((((I2C1->SR1) >> 1)&0x01)!=0x00); //czekaj az wyzeruje sie flaga ADDR
dummy = I2C1->SR1;
dummy = I2C1->SR2; //skasuj ewentualne flagi
}
void I2CSend(uint8_t data)
{
uint16_t dummy;
I2C1->DR = data;
while((((I2C1->SR1) >> 7)&0x01)!=0x01);
dummy = I2C1->SR1;
dummy = I2C1->SR2; //skasuj ewentualne flagi
}
uint8_t I2CRead(uint8_t ack)
{
uint16_t dummy;
if(ack)
I2C1->CR1 |= (uint16_t)(0x01 << 10);
else
I2C1->CR1 &= ~((uint16_t)(0x01 << 10));
while((((I2C1->SR1) >> 6)&0x01)!=0x00);
dummy = I2C1->SR1;
dummy = I2C1->SR2; //skasuj ewentualne flagi
return((uint8_t)(I2C1->DR));
}
void I2CStop(void)
{
uint16_t dummy;
I2C1->CR1 |= (uint16_t)(0x01 << 9);
dummy = I2C1->SR1;
dummy = I2C1->SR2; //skasuj ewentualne flagi
}
Below how the transmission is called from main function
Code:
I2CStart();
I2CAddr(0x70|WRITE); //IC16
I2CSend(0xAA);
I2CStop();
I2CStart();
I2CAddr(0x7E|WRITE); //IC17
I2CSend(0x55);
I2CStop();
Addresses are OK, chips send ACKs when they're supposed to but do not change output states. Sometimes I succeed when I'm performing step-by-step debugging...
Could anyone have a look and help me find a solution, please?
BRegards
Damian