This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC output to UART

Other Parts Discussed in Thread: LM3S3748

Hi, I am using Stellaris LM3S3748 EVP, I wrote a code to use both ADC as an input (pin ADC0) and I want to write the output of the ADC to UART, I am concern about the following

 

1-  ADC output is 12-bit the UART works with 1-N-8 operation, is it wrong if I wrote the output to the UART in this case ?

 

2-  The warning #16032-D object files have incompatible wchar_t types ("C:/StellarisWare/driverlib/sourcerygxx/libdriver.a<uart.o>" = --wchar_t=32, "./lm3s3748_startup_ccs.obj" = --wchar_t=16) ProjectConfig C/C++ Problem  [ is that a serious problem ???]

 

3-  If there is some thing wrong in my code given that the code works without errors, I just want to know if there is some instructions missing or redundant.

The below is my code

#include "hw_types.h"
#include "hw_memmap.h"
#include "driverlib/adc.h"
#include "inc/lm3s3748.h"
#include <stdio.h>
#include "driverlib/gpio.h"
#include "hw_types.h"
#include "utils/ustdlib.h"
#include "grlib/grlib.h"
#include "driverlib/uart.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/rom.h"
#include "driverlib/debug.h"
#include "inc/hw_ints.h"


void main()
{
	unsigned long ADC0Value[1];

	SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);

	IntMasterEnable();

	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));

	UARTEnable(UART0_BASE);

	UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

	ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);

	ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);

	ADCSequenceEnable(ADC0_BASE, 3);

	ADCIntClear(ADC0_BASE, 3);



	while(1)
	 {

	ADCProcessorTrigger(ADC0_BASE, 3);

	while(!ADCIntStatus(ADC0_BASE, 3, false))
	{}

	ADCIntClear(ADC0_BASE, 3);

	ADCSequenceDataGet(ADC0_BASE, 3, ADC0Value);

    unsigned char y= ADC0Value[0];

    UARTCharPut(UART0_BASE, y);

	}
}

 

Thanks in advance.

 

  • This post stems from your earlier efforts w/your MCU's ADC.   Again - note that your EVB has (long) been discontinued - any damage will (most likely) prove fatal to your project.    (and earlier I've suggested that you migrate to vendor's newer devices - which are replaceable...)

    Again - as mentioned in a previous response - you must fully consider:

    • how to make your 32 bit (w/only 12 bits active) ADC result compatible w/an 8 bit UART
    • the consequence of placing that (relatively) "s  l  o  w" UART transmit w/in your ADC interrupt handler

    You are developing your ability to recognize issues - many/most have been "bumped against" by others here.   (and resolved)

    A "forum search" - tuned to these issues - will enhance your knowledge & problem-solving capabilities.  (not my wish to deprive you of that satisfaction/learning...)