I'm new in { STM32F4-Discovery board-ChibiOS-ChibiStudio } 'combo'.
I tried to send few bytes to an serial eeprom (24FC512), but just the control byte was sent, data not.
I would like create an simple code to teach others, but I was unsuccessful.
My code is: (I think I have well configured project)
static const I2CConfig i2ccfg =
{
1, // Using the bus as I2C bus
400000, // Clock speed
1, // Standard fast mode duty cycle
};
/*=======================================================*/
/* Main thread , the entry point of Application */
/*=======================================================*/
int main(void)
{
halInit(); chSysInit(); // System init.
//Thread *shelltp = NULL; mShellInit(); // Shell config.
///////////////////////////////////////////////////////
i2cStart(&I2CD1, &i2ccfg);
palSetPadMode(GPIOB,7,PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
palSetPadMode(GPIOB,8,PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);
i2caddr_t addr=0x51; msg_t i2cmsg=0; msg_t ERRR=0;
uint8_t psh[3]={0x00,0x01,'A'}; uint8_t rcv[3]={0,0,0};
while (TRUE) // main program
{
i2cAcquireBus(&I2CD1);
i2cmsg=i2cMasterTransmitTimeout(&I2CD1, addr, psh, 2, NULL, 0, TIME_INFINITE);
if (i2cmsg != RDY_OK) ERRR = i2cGetErrors(&I2CD1);
i2cReleaseBus(&I2CD1);
chThdSleepMilliseconds(2000);
}
i2cStop(&I2CD1);
}
------------------------------------------
I saw it on I2C bus (Analog Discovery protocol view):
[START|h51|ACK|STOP]
and not more data.
(I think I need: [START|h51|ACK|h00|ACK|h01|ACK|STOP])
We tried send data to the same bus (and address) from an Arduino, and this send all data.
What is wrong in my code?
Is possible, that the I2C works just in threads?
Thanks the answers, I wait for these!