2014-03-30 12:25 AM
hi guys. for gathering data from adxl345 accelerometer i need to write some data in specified register in this sensor. but in stm32f4xx_i2c.c there isn't any function like :
I2C_SendData(I2Cx, data);to write in a register which i know it's address.is there anybody to explain me the procedure of this matter, means connect adxl345(or any sensor which is connected through i2c ) through i2c to stm32f4 #stm32f4 #i2c #i2c #discovery #accelerometer #discovery #stm32f42014-04-02 03:42 AM
Hi
''is there anybody to explain me the procedure of this matter'' There are hundreds of threads all asking - how do I do I2C Many will have code examples in reply to the original post. Please search the forum for the information you require. In particular, look for examples from a poster called clive1 He provides the best example code. If you have problems - then ask again.2014-04-03 01:38 PM
hi ,i searched a lot but i couldn't find any thing useful ,(maybe the problem is me), after some effort i could get the data of adxl345, but now i have a question, when i want to get a data (for example X axis data(DATAX0)) i have to write it's register address in this sensor, this sensor has 6 register that saving data in them, DATAX0,DATAX1,DATAY0,DATAY1,DATAZ0,DATAZ1,
if i want to gather all of these 6, i have to always send these 6 register address to sensor in my while loop ? i mean there isn't any configuration in it that i can make it to give me there 6 value just with 1 initialization ??i don't want to hold micro always busy just for sending this value to my sensor. thank2014-04-03 02:22 PM
I2C slaves typically have internal register address auto-incrementing. ie you select the base register, and the read back 6 consecutive register content.
2014-04-04 07:38 AM
2014-04-04 08:50 AM
i think i have to always send the registers addresses
You're clearly reading somehttp://www.analog.com/static/imported-files/data_sheets/ADXLpdf
. Pg 18 wrt I2C ''Single - or multiple - byte reads/writes are supported, as shown in Figure ''
I2C_start(I2C1, 0xA6 , I2C_Direction_Transmitter);
I2C_start(I2C1,0xA7 , I2C_Direction_Receiver);
The direction setting should already infer the state of Bit 0 in the address (DEVICE << 1)
I really can't help you with I2C stuff, I don't like it, and really dislike the ST implementation. I'm not specifically familiar with the ADXL
2014-04-04 09:09 AM
If you want to receive multiples bytes at once, it is *very* important to set the Acknowledge flag *before* waiting the
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED
event: change your I2C_Start function that way.
2014-04-04 09:24 AM
Hi
''but it has problem,when i unplug the discovery board usb from pc and plug it again and program the stm32f407vg , it programs well, but when i want to change a line of my code and reprogram it, i have to reset board from reset button to pass this line of my code : while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY)); i don't find the problem ,but i'm trying to, i have to add, i send it's data to pc through usart. but the problem which i mentioned make me doubt about my code and the accuracy of these data :)'' It sounds like you are trying to do this by looking at what the processor can output. You need to use a debugger. You mentioned that you are using a Discovery board. This board has an on board ST Link debugger. There are a number of free Intergeted Developmen Enviroment (IDEs) that will work with this. These will allow you to debug to a line of code. Try : IAR Workbenck (free edition limited to 32K) Keil (free edition also limited to 32K) em:Blocks CooCox to name but a few. This should get over your problems of having to reboot to program etc2014-04-04 11:48 PM
hi
gonzalez.laurent
in my code i put this
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED
after all of my flag flags.would you explain more about ''Acknowledge flag'' which i have to put befor the event you mentioned??thanks in advance2014-04-05 12:30 AM
This is required by the I2C protocol: when a byte is send from one side (master or slave), the other side must acknowledge the reception.
When you read bytes from the slave, the master side must acknowledge, this is exactly what the ACK bit in control register does. As soon as a single byte is not acknowledge, the slave will consider that the transfer is finished. As soon as the master is put in receive mode, it starts to clock data in from the slave, so it is *very* important to set ACK bit before the clock starts.