Page 1 of 1

PLS - help in I2C in ChibiOS

Posted: Fri Jul 12, 2013 2:11 pm
by n0rbee
Hello,

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. :oops:
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] :roll:

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! :)

Re: PLS - help in I2C in ChibiOS

Posted: Fri Jul 12, 2013 2:43 pm
by Giovanni
Hi,

I think barthess could answer this, I don't see obvious errors.

Anyway, try our IRC channel, the I2C expert is often there: http://www.chibios.org/dokuwiki/doku.ph ... os:support

Giovanni

Re: PLS - help in I2C in ChibiOS

Posted: Fri Jul 12, 2013 2:58 pm
by Tectu
Also, we wrote this guide. You might want to give it a shot too.

P.S. could you please use code boxes to post code in your future posts?


~ Tectu

Re: PLS - help in I2C in ChibiOS

Posted: Mon Jul 22, 2013 6:47 pm
by barthess
n0rbee
Please take a look at this topic viewtopic.php?f=16&t=1312&p=11674#p11674

Re: PLS - help in I2C in ChibiOS

Posted: Thu Aug 08, 2013 3:20 pm
by n0rbee
Thanks for all relpies, I spent new weeks with this problem, and... :twisted:

On I2CD3 works fine with the specified code.
This is the only one bus on which there are no other device on DISCOVERY board.
I think the open drain output is not working when other devices (with not i2C) are connected to the pin of bus (I2CD1, I2CD2).
I hope, this post will be helpful for others too.

Thanks!