Nguyentridung
Thành Viên PIF
Em đang dùng I2C để giao tiếp với cảm biến gia tốc MMA8452Q, đoạn code em viết như sau:
#include <msp430.h>
#include "I2C.h"
#include "Basic_Config.h"
unsigned int dataxyz[6];
int x_acce, y_acce, z_acce;
/*
* main.c
*/
void main() {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
Config_Clocks();
i2c_init(0x1C);// 0: write; 1: read; address 0011100
_delay_cycles(500000);
i2c_write(0x2A,1,0x18); // Output Data Rate 100KHz
i2c_write(0x0E,1,0x00); // Output buffer format Full scale (2g) 1024/g
while (1){
i2c_read(0x01,6,dataxyz);
x_acce = (dataxyz[0]<<4) + (dataxyz[1]>>4);
y_acce = (dataxyz[2]<<4) + (dataxyz[3]>>4);
z_acce = (dataxyz[4]<<4) + (dataxyz[5]>>4);
}
}
Sau khi đổ code thì không có lỗi, warning: function declared implicitly ngay chỗ cái i2c_write(,,). debug thì thấy nó không thoát được khỏi vòng lặp trong hàm i2c_write. Cả 2 hàm i2c_write và i2c_read em lấy trong driver chép hôm bữa.
Không biết code em viết sai chỗ nào, anh xem dùm em.
Em cảm ơn
#include <msp430.h>
#include "I2C.h"
#include "Basic_Config.h"
unsigned int dataxyz[6];
int x_acce, y_acce, z_acce;
/*
* main.c
*/
void main() {
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer
Config_Clocks();
i2c_init(0x1C);// 0: write; 1: read; address 0011100
_delay_cycles(500000);
i2c_write(0x2A,1,0x18); // Output Data Rate 100KHz
i2c_write(0x0E,1,0x00); // Output buffer format Full scale (2g) 1024/g
while (1){
i2c_read(0x01,6,dataxyz);
x_acce = (dataxyz[0]<<4) + (dataxyz[1]>>4);
y_acce = (dataxyz[2]<<4) + (dataxyz[3]>>4);
z_acce = (dataxyz[4]<<4) + (dataxyz[5]>>4);
}
}
Sau khi đổ code thì không có lỗi, warning: function declared implicitly ngay chỗ cái i2c_write(,,). debug thì thấy nó không thoát được khỏi vòng lặp trong hàm i2c_write. Cả 2 hàm i2c_write và i2c_read em lấy trong driver chép hôm bữa.
Không biết code em viết sai chỗ nào, anh xem dùm em.
Em cảm ơn

), với lại đọc i2c bạn kiểm tra thử xem mấy byte đầu tiên của dữ liệu đọc về có phải là dữ liệu bạn cần không nhé.