Hi,
I was writing the code for display of ADC via UART.
My code->
------------------------------------------------------------------------------------------------------------------
/* For usleep() */
#include <unistd.h>
#include <stdint.h>
#include <stddef.h>
#include <xdc/runtime/System.h>
/* Driver Header files */
//#include <ti/drivers/GPIO.h>
#include <ti/drivers/ADC.h>
#include <ti/display/Display.h>
// #include <ti/drivers/I2C.h>
// #include <ti/drivers/SDSPI.h>
// #include <ti/drivers/SPI.h>
#include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>
/* Board Header file */
#include "Board.h"
/* global variableS FOR GUI COMPOSER */
uint16_t adc_Value = 0;
uint16_t threshold = 100;
uint16_t trigger = 0;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
/* 1 second delay */
uint32_t time = 100000;
/* Call driver init functions */
// GPIO_init();
ADC_init();
// I2C_init();
// SDSPI_init();
// SPI_init();
UART_init();
// Watchdog_init();
/* Open Display Driver */
Display_Handle displayHandle;
Display_Params displayParams;
Display_Params_init(&displayParams);
displayHandle = Display_open(Display_Type_UART, NULL);
/* Open ADC Driver */
ADC_Handle adc;
ADC_Params params;
ADC_Params_init(¶ms);
adc = ADC_open(Board_ADC0, ¶ms);
if (adc == NULL) {
while (1);
}
/*Open UART driver*/
UART_Handle handle;
UART_Params params1;
UART_Params_init(¶ms1);
params1.baudRate = 115200;
params1.writeDataMode = UART_DATA_BINARY;
params1.readDataMode = UART_DATA_BINARY;
params1.readReturnMode = UART_RETURN_FULL;
params1.readEcho = UART_ECHO_OFF;
handle = UART_open(Board_UART0, ¶ms1);
if (!handle) {
System_printf("UART did not open");
}
while (1) {
// int_fast16_t adc_Value;
int_fast16_t ret;
int_fast16_t ret1;
ret = ADC_convert(adc, &adc_Value);
if (ret == ADC_STATUS_SUCCESS) {
Display_printf(displayHandle, 1, 0, "ADC Reading %d", adc_Value);
if(adc_Value >= threshold){
ret1= UART_write(handle,adc_Value,sizeof(adc_Value));
Display_printf(displayHandle, 1, 0, "ADC Reading %d", ret1);
//System_printf("The UART wrote %d bytes\n", ret);
trigger=1;
} else{
ret1=UART_write(handle,adc_Value,sizeof(adc_Value));
Display_printf(displayHandle, 1, 0, "ADC Reading %d", ret1);
// System_printf("The UART wrote %d bytes\n", ret);
trigger = 0;
}
}
usleep(time);
}
}
-----------------------------------------------------------------------------------------------------------------------
I didnt get the output in teraterm .I used display driver.
I have to use buffer in <UART_write(handle,adc_Value,sizeof(adc_Value));> or it will work please suggest.
With regards,
Sayam