Feb 23, 2015
04:42 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 23, 2015
04:42 PM
problems sending data of adc and uart :
#include <device.h>
/* Macro definitions */
#define DELAY (5000u)
/* Resistor Values */
volatile uint32 windowFlag = 0u;
volatile uint8 dataReady = 0u;
/* Send the channel number and voltage to UART */
static void SendChannelVoltage( int16 mVolts);
/* Interrupt prototypes */
CY_ISR_PROTO(ADC_ISR_Handler);
void main()
{
int16 mVolts = 0;
/* Start the Components */
ADC_Start();
IDAC_Start();
UART_Start();
/* Start ISRs */
ADC_IRQ_StartEx(ADC_ISR_Handler);
/* Enable global interrupts */
CyGlobalIntEnable;
/* Start ADC conversion */
ADC_StartConvert();
for(;;)
{
CyDelay(DELAY);
/* Wait for ADC conversion */
while(dataReady == 0u)
{
}
/* Convert the ADC counts to mVolts. ADC is configured to be single channel */
mVolts = ADC_CountsTo_mVolts(0u, ADC_GetResult16(0u));
SendChannelVoltage( mVolts);
dataReady = 0u;
}
}
static void SendChannelVoltage( int16 mVolts)
{
/* Clear Screen */
/* Print Channel */
UART_UartPutString(" Channel = ");
/* Display the channel number starting from 1 */
/* Convert Channel number to ASCII and send */
/* Send Volts to UART */
UART_UartPutChar(mVolts);
UART_UartPutString(" mV");
UART_UartPutCRLF(0u);
}
/******************************************************************************
* Function Name: ADC_ISR_Handler
*******************************************************************************
*
* Summary:
* Interrupt Service Routine. Check the ADC status and sets window and data
* ready flags.
*
******************************************************************************/
CY_ISR(ADC_ISR_Handler)
{
uint32 intr_status;
/* Read interrupt status registers */
intr_status = ADC_SAR_INTR_MASKED_REG;
/* Check for End of Scan interrupt */
if((intr_status & ADC_EOS_MASK) != 0u)
{
/* Read range interrupt status and raise the flag */
windowFlag = ADC_SAR_RANGE_INTR_MASKED_REG;
/* Clear range detect status */
ADC_SAR_RANGE_INTR_REG = windowFlag;
dataReady = 1u;
}
/* Clear handled interrupt */
ADC_SAR_INTR_REG = intr_status;
}
1 Reply
Feb 23, 2015
06:33 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Feb 23, 2015
06:33 PM
You have to change this -
UART_UartPutChar(mVolts);
to this -
char strbuff[ 20 ];
sprintf( strbuff, "%i4, 10", mVolts ); // Convert mVolts to a string
UART_UartPutString( strbuff );
To enable the nano library (to handle sprintf and floats) -
http://airsupplylab.com/index.php/learn/14-psoc5/9-psoc-floating-point-problem-in-psoc-creator-3 nano library enable
http://www.cypress.com/?id=4&rID=87354 nano library enable
Formatting strings for sprintf attached.
Set Heap and Stack to 0x0100 and 0x0400 respectively, to be able to handle the nano library.
Regards, Dana.