XMC4500 sending values from ADC to USB

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User11520
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted
Hello everyone,
I am trying to acquire a voltage with my XMC4500 Relax Kit and then transmit the value through USB.

I am using the ADC_MEASUREMENT app activated every 1s by a TIMER app and it works fine. Then I have problems with the USB transmission.
I am using the USBD_VCOM app and I understand that the problem is the type of the value to be sent.
For example, if I try to send the character 'a' by writing
TxBuffer[0] = 'a' 

I properly see the character 'a' on my Putty terminal.
On the contrary I did non understand how to send numbers up to 4096. Although I think that only few lines of code are missing, I tried different already posted solution with no success.
Can you help me?
Emanuele

 
#include

uint32_t event_count;
uint32_t result_Isignal;
uint32_t i = 0;
bool Isignalstatus = 0;
int8_t TxBuffer[64];


int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init();
if (status == DAVE_STATUS_FAILURE)
{
XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
while (1U)
{
}
}

if(USBD_VCOM_Connect() != USBD_VCOM_STATUS_SUCCESS)
{
return -1;
}

while(!USBD_VCOM_IsEnumDone());

ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);

while (1U)
{
if (Isignalstatus==1)
{
TxBuffer[0] = result_Isignal;
USBD_VCOM_SendByte(TxBuffer[0]);
CDC_Device_USBTask(&USBD_VCOM_cdc_interface);
Isignalstatus = 0;
}
}

return 1;
}


void Time_Interval_Event(void)
{
/* Acknowledge Period Match interrupt generated on TIMER_CCU_1 */
TIMER_ClearEvent(&TIMER_0);
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);
}

/*End of measurements interrupt*/
void Adc_Measurement_Handler(void)
{
/*Read out conversion results*/
result_Isignal = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Isignal_handle);
Isignalstatus = 1;

}


0 Likes
1 Solution
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi Emanuele,

I have modified your code. Kindly check whether this works.

Modified Code:

 uint32_t event_count;
uint32_t result_Isignal;
uint32_t i = 0;
bool Isignalstatus = 0;
int8_t TxBuffer[64];


int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init();
if (status == DAVE_STATUS_FAILURE)
{
XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
while (1U)
{
}
}

if(USBD_VCOM_Connect() != USBD_VCOM_STATUS_SUCCESS)
{
return -1;
}

while(!USBD_VCOM_IsEnumDone());

ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);

while (1U)
{
if (Isignalstatus==1)
{
sprintf(TxBuffer,"\n\rResult=%d",result_Isignal);

for(int i=0;TxBuffer != '\0';i++)
{
USBD_VCOM_SendByte(TxBuffer);
CDC_Device_USBTask(&USBD_VCOM_0);
}


Isignalstatus = 0;
}
}

return 1;
}


void Time_Interval_Event(void)
{
/* Acknowledge Period Match interrupt generated on TIMER_CCU_1 */
TIMER_ClearEvent(&TIMER_0);
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);
}

/*End of measurements interrupt*/
void Adc_Measurement_Handler(void)
{
/*Read out conversion results*/
result_Isignal = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A_handle);
Isignalstatus = 1;

}


Best Regards,
Vasanth

View solution in original post

0 Likes
2 Replies
Vasanth
Moderator
Moderator
Moderator
250 sign-ins 500 solutions authored First question asked
Hi Emanuele,

I have modified your code. Kindly check whether this works.

Modified Code:

 uint32_t event_count;
uint32_t result_Isignal;
uint32_t i = 0;
bool Isignalstatus = 0;
int8_t TxBuffer[64];


int main(void)
{
DAVE_STATUS_t status;

status = DAVE_Init();
if (status == DAVE_STATUS_FAILURE)
{
XMC_DEBUG(("DAVE Apps initialization failed with status %d\n", status));
while (1U)
{
}
}

if(USBD_VCOM_Connect() != USBD_VCOM_STATUS_SUCCESS)
{
return -1;
}

while(!USBD_VCOM_IsEnumDone());

ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);

while (1U)
{
if (Isignalstatus==1)
{
sprintf(TxBuffer,"\n\rResult=%d",result_Isignal);

for(int i=0;TxBuffer != '\0';i++)
{
USBD_VCOM_SendByte(TxBuffer);
CDC_Device_USBTask(&USBD_VCOM_0);
}


Isignalstatus = 0;
}
}

return 1;
}


void Time_Interval_Event(void)
{
/* Acknowledge Period Match interrupt generated on TIMER_CCU_1 */
TIMER_ClearEvent(&TIMER_0);
ADC_MEASUREMENT_StartConversion(&ADC_MEASUREMENT_0);
}

/*End of measurements interrupt*/
void Adc_Measurement_Handler(void)
{
/*Read out conversion results*/
result_Isignal = ADC_MEASUREMENT_GetResult(&ADC_MEASUREMENT_Channel_A_handle);
Isignalstatus = 1;

}


Best Regards,
Vasanth
0 Likes
User11520
Level 2
Level 2
10 replies posted 10 questions asked 5 replies posted
Hi Vasanth,
yes, it works, thank you for your help!
0 Likes