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-05-07 02:08 AM
Hi Armoun
Ok I tried testing my code to see if my USART connection was working, because it would be stupid if that didn't work... So in the main loop I commented all of the sensor readings and just put this: USART_SendData(USART3, 0x34);In the while(1) loop.. Then I opened the port with the application you mentioned and put the data mode on hex the result was: 00 FC 00 FC 00 FC 00 FC ..... (which after googling it seems to be the Ü character) Any Idea why it seems to change the value? Sending 0x01 gives 1C as an output.. I just tested also the readout of the sensor and there it is also almost the same (FC 00 00 E0 1C E0 00 FC FC, this keeps repeating) and when I move the sensor the hex data doesn't change so there is still something wrong..Greetings Ben2014-05-09 05:34 AM
Hi Armoun.mohamad
I finally succeeded in reading out all of the axes of the sensor, found a person online who wrote his own libraries for the STM32F429 based on the standard ST libraries ( ). So now I receive the data in hex in my terminal. (it is stable if I don't move the sensor) I am now trying to display it in the terminal in ASCII but I don't know if it is even possible to convert it into ASCII symbols before sending them through serial.. At the moment I have written the following function to merge the data to 1 data for each axis:void
comb_DATA(uint16_t data_axis [], uint8_t data[]){
data_axis[0] = (data[1] << 8) | data[0];
data_axis[1] = (data[3] << 8) | data[2];
data_axis[2] = (data[5] << 8) | data[4];
}
but when sending this data through serial just gives me the MSB of the axis and not the complete 2 byte of data.
Is it even possible what I try to do? Or do I need to have an extra program on my pc to read out the correct data (in ASCII)?
Greetings
Ben
2014-05-09 06:31 AM
hi ben
well done. the pint is usart send 1 byte each time so if you want to send it by usart you have to use this conversion(each axis to 1 number) in pc.i mean you have to create a program with c or c++ or java or c# or .... in pc to read from your serial port . if you cant program in pc you can convert the each axis number to string (a array of char) and then send this string trough usart. note that , as i mentioned usart send 8bit or 1byte each time and you convert integer to string you must send each char per time. because char is 1byte.here is some example about converting integer to string in c and c++:http://www.cplusplus.com/articles/D9j2Nwbp/%20
http://www.cplusplus.com/reference/string/to_string/
http://www.cplusplus.com/forum/beginner/7777/
http://stackoverflow.com/questions/9655202/how-to-convert-integer-to-string-in-c
http://stackoverflow.com/questions/5242524/converting-int-to-string-in-c
2014-11-01 10:59 AM
Hi Mohamad,
I use your code and I read all values of the sensor. Thanks for that. Now I try to display that on HD447 I've got a library for that and I can display other 8-bit and 16-bit variables (convert that to char with sprintf function). However I've got a troubles with values which I read of the sensor. I'm not sure if I do it correctly, my code:ReadFromAccel(DATAX0);
I2C_start(I2C1,0xA7 , I2C_Direction_Receiver);
buffer[0] = I2C_read_nack(I2C1);
Delay(0xFFFF);
ReadFromAccel(DATAX1);
I2C_start(I2C1,0xA7 , I2C_Direction_Receiver);
buffer[1] = I2C_read_nack(I2C1);
Delay(0xFFFFa);
data_axis = (int16_t)((buffer[1] << 8) | buffer[0]);
sprintf (buffer1, ''X: %d'', data_axis);
TM_HD44780_Puts(0, 1, buffer1);
Is it a good way to read and display the axes of the sensor?