16 #include "../firmware.h"
18 #include "inc/hw_i2c.h"
19 #include "inc/hw_memmap.h"
20 #include "inc/hw_types.h"
22 #include "driverlib/gpio.h"
23 #include "driverlib/i2c.h"
24 #include "driverlib/pin_map.h"
25 #include "driverlib/sysctl.h"
30 #define DEBUG_SERIAL UART_CAMERA // this is the serial port debug messages will come through (UART_CAMERA or UART_GNSS)
31 #define GPS_SERIAL UART_GNSS
32 #define CAM_SERIAL UART_CAMERA
34 #define DEBUG_SERIAL GPS_SERIAL
38 #define SLAVE_ADDRESS 0x68 // this is the MPU-9250A i2c address %1011000
43 #define MPU_GYRO_CONFIG 27
44 #define MPU_ACCEL_CONFIG 28
45 #define MPU_ACCEL_XOUT 59
46 #define MPU_ACCEL_YOUT 61
47 #define MPU_ACCEL_ZOUT 63
48 #define MPU_TEMP_OUT 65
49 #define MPU_GYRO_XOUT 67
50 #define MPU_GYRO_YOUT 69
51 #define MPU_GYRO_ZOUT 71
52 #define MPU_WHO_AM_I 117
53 #define MPU_INT_BYPASS_ENABLE 55
58 #define STRING_BUFFER_LENGTH 20 // rough hack for testing
60 static char string_buffer[STRING_BUFFER_LENGTH];
61 static char string_buffer2[STRING_BUFFER_LENGTH];
63 static void UART_putnum(
unsigned int serialport,
signed long x)
65 itoa(abs(x),string_buffer,16);
66 unsigned int len=strlen(string_buffer);
67 unsigned int targetlen=6-len;
68 strcpy(string_buffer2,
"+00000");
69 strcpy(string_buffer2+targetlen,string_buffer);
70 if (x<0) string_buffer2[0]=
'-';
74 static void UART_putstr(
unsigned int serialport,
char *s1,
signed long x,
char *s2)
77 UART_putnum(serialport,x);
81 #define DISP3(x,y,z) UART_putstr(DEBUG_SERIAL,x,y,z); // x and z are strings, y is a number shown as signed base10 16bit
82 #define DISP2(y,z) UART_putstr(DEBUG_SERIAL,NULL,y,z);
83 #define DISP1(x) UART_puts(DEBUG_SERIAL,x);
84 #define DISP(x) UART_putc(DEBUG_SERIAL,x);
85 #define DISPW(x) UART_putc(DEBUG_SERIAL,x&0xff);UART_putc(DEBUG_SERIAL,x>>8);
96 setupwatchdoginterrupt();
102 #define MAG_PASS_THROUGH_I2C_ADDR 12
106 #define MAG_HZL 7 // offsets in magnetometer, note little endian, so need to be read opposite way round
107 #define MAG_CNTL1 10 // Magnetometer control register
108 #define MAG_STA1 2 // read only gives flags at 1 for DRDY and 2 for DOR (data ready and overload), used in read cycle
113 i2cstring[0]=MPU_INT_BYPASS_ENABLE;
114 char i2cstatus=I2CReceive(SLAVE_ADDRESS,MPU_INT_BYPASS_ENABLE,I2C2_BASE);
115 i2cstring[1]=i2cstatus | MPU_INT_BYPASS_ENABLE;
117 I2CSendString(SLAVE_ADDRESS, i2cstring,I2C2_BASE);
121 i2cstring[0]=MAG_CNTL1;
124 I2CSendString(MAG_PASS_THROUGH_I2C_ADDR, i2cstring,I2C2_BASE);
126 I2CSendString(MAG_PASS_THROUGH_I2C_ADDR, i2cstring,I2C2_BASE);
128 char mag_id=I2CReceive(MAG_PASS_THROUGH_I2C_ADDR,0,I2C2_BASE);
134 signed short acc_x,acc_y,acc_z,gyr_x,gyr_y,gyr_z,mag_x,mag_y,mag_z,temp;
137 #define MPUGET(x) I2CReceive16(SLAVE_ADDRESS,x,I2C2_BASE); // wrapper for I2C call to MPU
138 #define MAGGET(x) I2CReceive16r(MAG_PASS_THROUGH_I2C_ADDR, x,I2C2_BASE); // wrapper for I2C call to Magnetometer
140 DISP1(
"\n\n\n\rI2C IMU test - python compressed data version (use I2Ctest for human readable):\n\n")
145 acc_x=MPUGET(MPU_ACCEL_XOUT) acc_y=MPUGET( MPU_ACCEL_YOUT) acc_z=MPUGET(MPU_ACCEL_ZOUT)
146 gyr_x=MPUGET(MPU_GYRO_XOUT) gyr_y=MPUGET(MPU_GYRO_YOUT) gyr_z=MPUGET(MPU_GYRO_ZOUT)
147 temp=MPUGET(MPU_TEMP_OUT)
150 while ((I2CReceive(MAG_PASS_THROUGH_I2C_ADDR,MAG_STA1,I2C2_BASE)&1)!=1) {}
151 mag_x=MAGGET(MAG_HXL) mag_y=MAGGET(MAG_HYL) mag_z=MAGGET(MAG_HZL)
153 I2CSendString(MAG_PASS_THROUGH_I2C_ADDR, i2cstring,I2C2_BASE);
158 DISPW(acc_x) DISPW(acc_y) DISPW(acc_z)
159 DISPW(gyr_x) DISPW(gyr_y) DISPW(gyr_z)
160 DISPW(mag_x) DISPW(mag_y) DISPW(mag_z)
void UART_init(uint8_t uart_num, uint32_t baudrate)
int main(void)
Runs all module tests.
void UART_puts(uint8_t uart_num, char *str)