PLS - help in I2C in ChibiOS

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
n0rbee
Posts: 2
Joined: Fri Jul 12, 2013 1:41 pm

PLS - help in I2C in ChibiOS

Post 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! :)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PLS - help in I2C in ChibiOS

Post 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
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: PLS - help in I2C in ChibiOS

Post 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
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: PLS - help in I2C in ChibiOS

Post by barthess »

n0rbee
Please take a look at this topic viewtopic.php?f=16&t=1312&p=11674#p11674
n0rbee
Posts: 2
Joined: Fri Jul 12, 2013 1:41 pm

Re: PLS - help in I2C in ChibiOS

Post 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!
Post Reply