2010-12-09 09:11 AM
I2C not working
2011-05-17 05:17 AM
2011-05-17 05:17 AM
Hello alex,
I would point out the steps I needed to follow in order to make I2C work.2011-05-17 05:17 AM
WEll, now the I2C is in operational mode, but still not working quite right.
The clock line doesnt seem to generate a clock for starters, im trying to send a start signal, then the adress, then repeated start, then adrress again, etc. this is what im getting on the scope, and my code: the code: GPIOB_CRH = 0x0000DD00;//I2C lines are AF output open drain RCC_APB1ENR = 0x00400000; //enable I2C2 clock RCC_APB2ENR = 0x0000000D; //enable PA,PB,AF clock I2C2_OAR1 = 0x00004000; //bit 14 should be kept 1 by software I2C2_CR2 = 0x00000008; //frequency 36 mHZ, //enable event interrupts I2C2_CCR = 0x00000028; //clock configure I2C2_TRISE) = 0x00000009; // Rise time I2C2_CR1 = 0x00000401; //Enable ACK, Enable I2C while (1) { I2C2_CR1 |=0x00000100; //send START while(I2C2_SR1<1); //wait till START is complete delay(1); *(uint32*)(I2C2_DR) = 0b10010010; //while( (I2C2_SR1 >>1) <1); <- wait till address has been sent. If I use that line, the code gets stuck, meaning this condition isnt fulfilled delay(10); } thanks again!2011-05-17 05:18 AM
WEll, now the I2C is in operational mode, but still not working quite right. The clock line doesnt seem to generate a clock
Check you have the right pins, and there is a pull up on the clock pin. Better yet, use the library and example code.2011-05-17 05:18 AM
These are the right pins, and both have pull up resistors.
I really need to build this on my own, and not use libraries for the purposes of my project. Any other solutions & suggestions will be appreciated!2011-05-17 05:18 AM
Are you allowed to use library code and examples to test the hardware?
If you can isolate the probem to either hardware, or software, progress may be easier and quicker.2011-05-17 05:18 AM
I really need to build this on my own....
How fantastically ironic. Ok, what is your clock rate for the APB1? I'd guess from the settings 8 MHz, but your comments suggest 36 MHz, so which is it?2011-05-17 05:18 AM
I really need to build this on my own....
How fantastically ironic.
hehe, by ''on my own'' I meant ''manually'', not alone, in the dark, without internet :) As for the clock rate, its 8 MHz, the comments for the I2C2_xxx registers are wrong for some reason. I took all the clock settings from the reference manual, it has an exapmle for setting the right clock rates for 100 kHz speed