嗨,
我正在开发包含I2C
通信的应用程序,所以我已经实现了AN8231的代码。
到目前为止它工作正常,我在input_buf []中从I2C外设获得数据。数据有效,我可以在调试器会话的监视窗口中看到它们。但是当我尝试使用数据时:
Raw_X_L = input_buf [0];
它始终是0x00,这是无效值(来自监视窗口)。
这是代码:
u8 input_buf [MAX_INPUT]; //接收缓冲区
u8 output_buf [MAX_OUTPUT]; //传输缓冲区
...
...
void Read_M(void)
{
output_buf [0] =(OUT_X_L_M | 0x80);
while(!I2C_WriteRegister(lsm9ds0_xm_addr,SEV_BIT_ADDRESS,STOP,0x01,& output_buf [0]));
while(!I2C_ReadRegister(lsm9ds0_xm_addr,SEV_BIT_ADDRESS,STOP,0x06,& input_buf [0]));
}
...
...
Raw_X_L = input_buf [0];
如何将input_buf []中的数据分配给变量?同时我可以从output_buf []中分配值。
编译器是COSMIC STM8
最好的祝福,
沃伊
以上来自于谷歌翻译
以下为原文
Hi,
I'm developing applica
tion which include I2C communication, so I have implemented code from AN8231.
So far it works fine and I got data from I2C peripheral in input_buf[]. Data are valid, and I can see them in watch window in the debugger session. But when I try to use data ie:
Raw_X_L = input_buf[0];
it is always 0x00 which is not valid value (from watch window).
Here is code:
u8 input_buf[MAX_INPUT]; //receiving buffer
u8 output_buf[MAX_OUTPUT]; //transmitting buffer
...
...
void Read_M (void)
{
output_buf[0] = (OUT_X_L_M | 0x80);
while (!I2C_WriteRegister(lsm9ds0_xm_addr,SEV_BIT_ADDRESS, STOP, 0x01, &output_buf[0]));
while (!I2C_ReadRegister(lsm9ds0_xm_addr, SEV_BIT_ADDRESS, STOP, 0x06, &input_buf[0]));
}
...
...
Raw_X_L = input_buf[0];
How to assign data from input_buf[] to variable? At the same time I can assign value from output_buf[].
Compiler is COSMIC STM8
Best regards,
Vojislav
0