Page 1 of 1

problem with i2c and include

Posted: Thu May 22, 2014 11:36 am
by lesto
Hi,
i'm new to souch complex project and i've some problem with i2c.

i've started from the STM32f£discovery example, as in the wiki "start with eclipse" or similar.

I've changed #define HAL_USE_MMC_SPI to TRUE, and I2CConfig structure get used, but OPMODE_I2C, FAST_DUTY_CYCLE_2, and almost all enum/function give an error as not defined. Everything is done in the main file.

what i'm missing?

Re: problem with i2c and include

Posted: Thu May 22, 2014 12:24 pm
by Giovanni
Hi,

HAL_USE_MMC_SPI is not related to I2C, did you enable the I2C driver too?

Giovanni

Re: problem with i2c and include

Posted: Thu May 22, 2014 12:56 pm
by lesto
wops sorry, stupid copy paste, i mean HAL_USE_I2C. befor setting this to true, even "I2CConfig " was on error as undefined. After the define to TRUE I2CConfig error was solved just to open up a lot of other undefined; what bother me is that some enum are on the same file of the I2CConfig structure, so i can't undertand WHY they are not recognized!

maybe helps: RDY_OK is not defined, looked at the code, and saw it is now MSG_OK; but still get udefined error

Please note i'm using master from github (this mean chibiOS v3, if i'm not completly wrong), maybe there is some other config i should do?


ps. keep up with your great work! è fantastico :)

Re: problem with i2c and include

Posted: Thu May 22, 2014 12:58 pm
by Giovanni
You have to enable the I2C units in mcuconf.h probably.

Giovanni

Re: problem with i2c and include

Posted: Thu May 22, 2014 1:15 pm
by lesto
#define STM32_I2C_USE_I2C1 TRUE

i THINK i've already done that, have to check this.. if that won0t work, i'll post full code and error, i'm sure i'm missing something basic like this

Re: problem with i2c and include

Posted: Thu May 22, 2014 9:29 pm
by lesto
gotcha, itis using i2cV2, witch does not declare that fields.

so there are diffent setup for different board, i was hoping for a "write once, run everywhere", but i'll get over it :)

Re: problem with i2c and include

Posted: Thu May 22, 2014 9:40 pm
by colin
lesto wrote:gotcha, itis using i2cV2, witch does not declare that fields.

so there are diffent setup for different board, i was hoping for a "write once, run everywhere", but i'll get over it :)


It's a great ideal, but at some point you have to connect the dots between the abstraction and the specific hardware implementation. In ChibiOS/RT you can write most of your code abstracted from the specific hardware, e.g. using the HAL driver API, exception for the HAL driver configuration structure definitions -- that is where you specify the hardware configuration, usually with some platform-specific fields like OPMODE_I2C, FAST_DUTY_CYCLE_2, etc. You have the power to at that level configure some specific features of particular hardware, in addition to standard stuff like UART baud rate, etc. that might be common to all drivers.

You can quite easily put those hardware-specific configuration structures in separate source files or even separate directories from the rest of the hardware-independent application code. Then you can target your application for multiple hardware platforms.

Re: problem with i2c and include

Posted: Fri May 23, 2014 10:01 am
by lesto
nice answer, if the hw-dependant code is only in conf, then i can try to do what you said.

is there a "collection" of example for that specific configuration? so i can try to add multi-board support without reading hundred of datasheet.

ps. is possible to use only main? becouse i've written a code with only a main and some i2c, cleaned and builded the project, uploaded it, but when i step into code i find strange beaviur like loop where there are no loop, and optimized out variable when they are used as argument for delay. Also some variable not optimized out give strange value, like an array of 'U' :D

also, tryed to set up a new project again from the demo (just to be sure i didn't break something), deleted the thread's code leaving just main, and it give me a compilation error about something not found about thread (I know, i should post the error and souch, but i'm experimenting on time stealed for sleep, this weekend i hope to do something better)

finally eclipse's indexer is quite bizarre, it give me "reference not found", but ctrl+click on function/variable open un the right file at line declaration. maybe is this that is broking debugger? please note others project debug fine.

my nobbiness is giving me a lot of problem :D