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 display problem

Other Parts Discussed in Thread: LM3S3748

Hello I am working with Stellaris lm3s3748

I wrote a code to read analog input signal from port ADC0 and write the output to pin U0TX to send the signal  to the PC and display it, but am getting the same output signal  (periodic pulses) what ever the analog in put is even without input the U0TX output is the same 

I hope someone can help me if there is any problem in the 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_TX);

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

  • Hello Mohammad

    Please note that you are writing the raw value and not the ASCII value. So on the Terminal program what you would be seeing is the equivalent ASCII. First check if the UART output on U0TX is the value as being sent by the UARTCharPut.

    Also you are taking a 12-bit value and writing it to a 8-bit data register. You would need two writes to send the data.
  • Hi Amit thanks for your reply

    Now I am thinking of using Direct register write to re-program the EVB (for more control ability) I can read the part of ADC and UART in the datasheet to know the names and the map of the registers I need, but my question now is do I access the register on CCS just by it's name e.g.
    ( UARTDR>> ; ) ??

    thanks in advance
  • I highly recommend you don't do that. Except in very narrow circumstances you do not gain control and you lose a good deal in readability (and write-ability) and debugging.

    Robert
  • Thanks Robert for your reply

    I really don't know what is wrong with my code I am freaking out of this problem all I want is to read analog signal and write the result to the UART I am new on Micro-controllers nearly no one in my country dealt with Stellaris lm3s3748 before, I am using it in My Graduation Project , it's the largest portion of the Project to Program the EVB, but I feel that am not close to program it before the deadline, I copied the example [single_ended.c ] and the error {#10010 errors encountered during linking;} appeared. [single_ended.c ] is the most related example I can learn from and I don't know any thing about the error and how we solve this problem and what are the steps needed to program the ADC to UART system.
  • mohammad sadoun said:
    I really don't know what is wrong with my code I am freaking out of this problem all I want is to read analog signal and write the result to the UART I am new on Micro-controllers

    That's quite a step up to start.

    Slow down and get the UART working first. There are several UART examples in TIVAWare. Once you have that working then you can add in the A/D. Right now you have several items you are trying to get working at once, that makes it hard for you to know where your problem lies.

    Robert

  • Oh, and it well help your helpers if you use the paste code option when providing your source (select use rich formatting and look for the <|> icon).

    Robert
  • Hello Mohammad,

    I would rather go for the approach

    unsigned char ucLowByte = ADC0Value[0] & 0xFF;
    unsigned char ucHighByte = (ADC0Value[0] & 0xFF00) >> 8 ;

    UARTCharPut(UART0_BASE, ucLowByte );
    UARTCharPut(UART0_BASE, ucHighByte );
  • thank you Robert for every thing, but what is the TIVAWare? is it helpful given that I am using Stellaris?

    Regards
  • thank you Amit this will help me alot :)
    thanks again
  • Sorry, forgot you were using an obsolete micro. Stellarisware is the older version.

    Robert
  • Hi Robert i wrote a code to configure the UART0 on my Stellaris lm3s3748 but I am getting strange output on the realterm software 

    the below is my code and a snapshot of the result, Can you tell me what is the problem in 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"
    
    int main(void) {
    
    	SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
    
    	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_TX);
    
    					while(1)
    						 {
    
     unsigned char x= "C";
    
    					    UARTCharPut(UART0_BASE, x);
    
    						}

    Result 

    Thanks in advance

  • The problem would be expecting an ASCII result when printing binary.

    To compare with the standard C library you are performing an fwrite rather than a fprintf.

    Robert
  • Thanks Robert how can I solve this problem is it in the code or on the setting of the RealTerm software?
    thanks in advance