Other Parts Discussed in Thread: TM4C123GH6PM
1. uart0 was used to get the sensor's value through the PA0 pin. But it failed to get it using uart5. And I do not know what the problem is.
2. Is it possible to use 4 sensors as tm4c129x? There are only 2 uarts (uart0, uart5) in my document. Can I not find it or tell me if I need to allocate it differently?
Here is my code.
#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void reverseArrayInt(int* array, int size) {
int temp;
int i=0;
for (i = 0; i < size / 2; i++) {
temp = array[i];
array[i] = array[(size - 1) - i];
array[(size - 1) - i] = temp;
}
}
void ConfigureUART(void) {
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
UARTStdioConfig(0, 115200, 16000000);
}
char *ushortToBinary(unsigned short i) {
static char s[16 + 1] = { '0', };
int count = 16;
do { s[--count] = '0' + (char) (i & 1);
i = i >> 1;
} while (count);
return s;
}
int main(void) {
uint32_t ui32SysClock;
volatile uint32_t ui32Loop;
char data_crnt;
int a,b,c,d,f,sum=0;
int i=0;
int j=0;
int k=1;
int result1[8];
int result2[8];
int temp8[8]={128,64,32,16,8,4,2,1};
int temp4[4]={8,4,2,1};
char Sync_After = 'b';
int Packet_TX_Index = 0;
char Data_Prev = 0;
char PUD0 = 0;
char CRD_PUD2_PCDT = 0;
char PUD1 = 0;
char PacketCount = 0;
char PacketCyclicData = 0;
char psd_idx = 0;
char PacketStreamData[200];
ROM_FPULazyStackingEnable();
ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
ConfigureUART();
while (1) {
data_crnt = UARTCharGet(UART0_BASE);
int retv = 0;
if (Data_Prev == 255 && data_crnt == 254)
{
Sync_After = 'a';
Packet_TX_Index = 0;
}
Data_Prev = data_crnt;
if (Sync_After == 'a')
{
Packet_TX_Index++;
if ((int)Packet_TX_Index > 1)
{
if (Packet_TX_Index == 2)
{
PUD0 = data_crnt;
}
else if (Packet_TX_Index == 3)
CRD_PUD2_PCDT = data_crnt;
else if (Packet_TX_Index == 4)
{
PacketCount = data_crnt;
}
else if (Packet_TX_Index == 5)
PUD1 = data_crnt;
else if (Packet_TX_Index == 6)
{
PacketCyclicData = data_crnt;
if((int)PacketCount==6)
{
a=(int)PacketCyclicData;
for(i=0;a>0;i++)
{
result1[i]=a%2;
a=a/2;
}
reverseArrayInt(result1,4);
for(i=0;i<4;i++)
{
sum=sum+result1[i]*temp4[i];
}
a=sum * 256;
sum=0;
}
else if((int)PacketCount==7)
{
b=(int)PacketCyclicData;
UARTprintf("%d\n",a+b);
(int)PacketCount=0;
}
}
}
else if (Packet_TX_Index > 6)
{
psd_idx = (Packet_TX_Index - 7);
PacketStreamData[psd_idx] = data_crnt;
}
}
if (Packet_TX_Index == (16 * 2 * 12 + 6))
{
Sync_After = 'b';
}
}
}