I can't run my code XMC4500

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

cross mob
MehdiJ
Employee
Employee
First like given First reply posted First question asked

Hello everyone,

I am trying to make the following code run. After building there seems to be no error and everything looks fine.

 #include <DAVE.h>
 // int8_t RxBuffer[64] = { 0 };
 // int8_t TxBuffer[64] = { 0 };
 uint8_t Bytes;
 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;

    }
	   /*
   {
     Bytes = USBD_VCOM_BytesReceived();

     if (Bytes)
     {

       USBD_VCOM_ReceiveByte(&RxBuffer[0]);

       USBD_VCOM_SendByte(RxBuffer[0]);

     }
     CDC_Device_USBTask(&USBD_VCOM_cdc_interface);
   }

   return 1;
 }
*/

Now my XMC4500 is connected to my laptop. After debugging I on

MehdiJ_0-1659608964369.png

I can't run the code after debugging as you can see. Also When Using Teraterm (instead of putty) there is no data flow. 

Best regards 🙂 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hello MehdiJ

I made an example with the KIT XMC4500 Relax Kit.

I used a timer to trigger the ADC reading every 200mS. I used the Hardware connection linking the timer on the ADC trigger.

At each trigger that is made by the ADC, it generates a callback and in this callback Pin, P14.15 is read.
Convert ADC reading to STRING, add \r and \n to 6 position vector. After that, I send the data to USBCOM

It was very simple and didactic, if you improve this code please buy it here it can help other people.

Best regards

View solution in original post

6 Replies
Rodrigo_RT
Level 4
Level 4
50 sign-ins 10 likes given 25 replies posted

Hello MehdiJ

I believe your problem is in the initialization of the timer interrupt or the ADC.

Start these interrupts after this part of the code.

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

as the timer could be interrupting the USB communication handshake and possibly crashing the MCU.

Best regards

Rodrigo

0 Likes
Rodrigo_RT
Level 4
Level 4
50 sign-ins 10 likes given 25 replies posted

Another point that can be seen is the 12Mhz crystal oscillator, for the USB to work properly it is necessary to use this 12Mhz crystal oscillator.

See you

0 Likes
MehdiJ
Employee
Employee
First like given First reply posted First question asked

@Rodrigo_RT  Thank you Rodrigo I will try this out and come back to you. But just to make everything clear  the code should look like this ?

 

#include <DAVE.h>
 // int8_t RxBuffer[64] = { 0 };
 // int8_t TxBuffer[64] = { 0 };
 uint8_t Bytes;
 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;
   }
    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;

    }

   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;
    }



 

And for the crystal oscillator, since I am a beginner here, I would assume that it has to do with some GUI parameter input right? Do you know which instance/App should be responsible for this?

0 Likes
lock attach
Attachments are accessible only for community members.

Hello MehdiJ

I made an example with the KIT XMC4500 Relax Kit.

I used a timer to trigger the ADC reading every 200mS. I used the Hardware connection linking the timer on the ADC trigger.

At each trigger that is made by the ADC, it generates a callback and in this callback Pin, P14.15 is read.
Convert ADC reading to STRING, add \r and \n to 6 position vector. After that, I send the data to USBCOM

It was very simple and didactic, if you improve this code please buy it here it can help other people.

Best regards

MehdiJ
Employee
Employee
First like given First reply posted First question asked

Thank you Rodrigo ! I will take a look at your work.

Also since I  did not use putty or teraterm before, can you please tell me how to be sure that data is sent using them? I connected to the right COM but still, I am not seeing data flowing. Only a blinking cursor. I built the project and debugged it. Still nothing seems to be poping-up.

 

UPDATE: I think that the OTG port or the cable linked to it are damaged .. 

Best 

Mehdi

0 Likes

Hello Mehdj

I made this example and tested it on my Relax Kit XMC4500, and it works perfectly.
Are you using the MCU USB port on the bottom of the kit on the side of the RJ45 Ethernet connector???

And you want an example using the XMC4500's UART and using the Programmer as a USB to Serial bridge.

I can send you too.

see you later.

0 Likes