I've continued work on this project and I have the following dilemma. The onboard temperature sensor is stored into a 32 bit variable, but only 12 bits are actually used. I then want to transfer that temperature over UART as I've mentioned throughout this post. UART can only handle 8 bits at a time. I've created a mask that stores the lower 8 bits into uartTemp[0] and the next 4 bits into uartTemp[1]. uartTemp is of the type uint8_t array. I am able to transmit uartTemp[0] and receive it properly but uartTemp[1] gets lost. I know that it is time for me to use an interrupt. I could really use a hand getting the interrupt set up, so that if a new temperature is available on UART it can be received properly. I also need to be concerned with receiving sequential packets(to handle the first 8 bits, and the second 8 bits). What would be the best way to accomplish this? Likewise, if I sent multiple temperature values back to back, I need a way of knowing what was sent and how to receive/handle it. I would appreciate your help in understanding and tackling this issue. Also, can you tell me how much current the TM4C123G battery monitoring uses? That'll be for a separate item that I will tackle. My code is pasted below: Transmitting side: #include #include #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" #include "utils/uartstdio.c" #include "driverlib/debug.h" #include "driverlib/adc.h" int main(void) { uint32_t ui32ADC0Value[4]; volatile uint32_t ui32TempAvg; volatile uint32_t ui32TempValueC; volatile uint32_t ui32TempValueF; uint32_t testdata = 4095; //00000000000000000000111111111111 int lowEight = 0b00000000000000000000000011111111; //Mask the lower 8 bits int middleFour = 0b0000000000000000000111100000000; //Mask bits 12downto8 uint8_t uartTemp[2] = {0}; //uint8_t uartTemp[2] to manipulate 32 bits //Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Enables UART1 for transmission. ("see" Data Collector) SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Configure the pins for UART1 GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); //Initialize the UART for console I/O. on UART0/BASE0 UARTStdioConfig(0, 9600, SysCtlClockGet()); //Set the baud rate, 8 data bits, one stop bit and no parity for UART0 UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); uartTemp[0] = testdata & lowEight; uartTemp[1] = (testdata & middleFour)>>8; SysCtlDelay(6000000); UARTCharPut(UART1_BASE, uartTemp[0]); UARTCharPut(UART1_BASE, uartTemp[1]); } The Receiving side: #include #include #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/gpio.h" #include "driverlib/pin_map.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" #include "utils/uartstdio.c" #include "driverlib/debug.h" #include "driverlib/adc.h" int main(void) { uint8_t uartTemp[2] = {0}; //Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ); //Enables UART1 for transmission. ("see" Data Collector) SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Configure the pins for UART1 GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTConfigSetExpClk(UART1_BASE, SysCtlClockGet(), 9600, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); /* UART Communication begins */ uartTemp[0] = UARTCharGet(UART1_BASE); SysCtlDelay(6000000); uartTemp[1] = UARTCharGet(UART1_BASE); SysCtlDelay(6000000); UARTprintf("Temp 0 is " + uartTemp[0]); UARTprintf("Temp 1 is " + uartTemp[1]); uint32_t concatTemp; concatTemp = uartTemp[1] + uartTemp[0]; }
↧