Professional Documents
Culture Documents
h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/uart.h"
#include "driverlib/pin_map.h"
#include "utils/uartstdio.h"
#include "inc/TM4C123GH6PM.h"
char Data_buffer[15]={0};
char Data_buffer1[15]={0};
char Data_buffer2[15]={0};
uint8_t Ax0, Ax1, Ay0 ,Ay1, Az0, Az1;
float X_out, Y_out, Z_out;
uint8_t buffer[8]={0};
reverse(str, i);
str[i] = ' ';
return i;
}
int main(void)
{
// Set the clocking to run directly from the external crystal/oscillator.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_INT |
SYSCTL_XTAL_16MHZ);
memset(Data_buffer,' ',sizeof(Data_buffer));
memset(Data_buffer1,' ',sizeof(Data_buffer1));
memset(Data_buffer2,' ',sizeof(Data_buffer2));
while(1)
{
/* I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAX0,1,&Ax0);
UARTprintf("AX0:%x\n\r",Ax0);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAX1,1,&Ax1);
UARTprintf("AX1:%x\n\r",Ax1);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAY0,1,&Ay0);
UARTprintf("AY0:%x\n\r",Ay0);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAY1,1,&Ay1);
UARTprintf("AY1:%x\n\r",Ay1);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAZ0,1,&Az0);
UARTprintf("AZ0:%x\n\r",Az0);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAZ1,1,&Az1);
UARTprintf("AZ1:%x\n\r",Az1);
I2C3_read_Multiple(ADXL345_SLAVE_ADRESS,DATAX0,6,&buffer[0]);
UARTprintf("%x %x %x %x %x %x\n\
r",buffer[0],buffer[1],buffer[2],buffer[3],buffer[4],buffer[5]);
SysCtlDelay(2000000);
memset(Data_buffer,0,sizeof(Data_buffer));
memset(Data_buffer1,0,sizeof(Data_buffer1));
memset(Data_buffer2,0,sizeof(Data_buffer2));
X_out = 0;
Y_out = 0;
Z_out = 0;
}
}
/*void InitUART0(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
}*/
void InitConsole(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
if (bytes_count <= 0)
return 1; /* no read was performed */
if (--bytes_count == 0)
{
while(I2C3_MCS_R & 0x40);
return 0;
}
I2C3_MCS_R = 5;
error = I2C_wait_till_done();
*data = I2C3_MDR_R;
while(I2C3_MCS_R & 0x40);
return 0; /* no error */
}