cancel
Showing results for 
Search instead for 
Did you mean: 

Sending float over serial communication

Bastien1
Associate III

Hello,

I'm actually trying to send data from the software Serial Port Monitoring to my dev board SPC574S-DISP.

But it doesn't work.

When i send a number like "3", it works.

But when i try to send "3,3" or "12", the board takes only the first number "3" or "1" and not the others.

Can you help me ?

I give you my main part if it can help you :

/* define a vector containing the channels to be converted */
#define NUMOFCHANNELS 1U
extern uint8_t anp[NUMOFCHANNELS];
extern float value[NUMOFCHANNELS];
extern float tension;
 
float tension;
uint8_t anp[NUMOFCHANNELS] = {5U};
float value[NUMOFCHANNELS] = {0U};
 
/* conversion callback */
void saradcconf_conv_cb(SARADCDriver *saradcp) {
  uint8_t i;
  /* Read converted channels */
  for (i = 0; i < NUMOFCHANNELS; i++) {
    value[i] = (tension*saradc_lld_readchannel(saradcp, anp[i]))/4095;
  }
}
 
/*
 * Application entry point.
 */
int main(void) {
 
  uint8_t i;
  SARADCDriver* driverUnderTest;
 
  /* change driverUnderTest value to test others SARADC modules. */
  driverUnderTest = &SARADC12D2;
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  /* Start Serial Driver */
   sd_lld_start(&SD2, NULL);
 
   /* Start SARADC Driver */
   saradc_lld_start(driverUnderTest, &saradc_config_saradcconf);
 
   // Asking tension value
   printf("\n Enter a numerator tension value \n");
   scanf("%f", &tension);
   printf("tension = %f \n", tension);
 
   /* start SARADC conversion */
   saradc_lld_start_conversion(driverUnderTest);
 
   // Waiting Time
   osalThreadDelayMilliseconds(1U);
 
   /* Application main loop.*/
   for (;;) {
 
     /* print converted value on serial port each 100ms */
     for (i = 0; i < NUMOFCHANNELS; i++) {
       printf("CHANNEL %d: VALUE: %f V ", anp[i], value[i]);
     }
     printf("\n\r");
     pal_lld_togglepad(PORT_E, PE_LED2);
     osalThreadDelayMilliseconds(100U);
  }
}

Thank you,

Sincerely

Bastion

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
zambrano.luigi
Senior III

Hi,

I have developed a simple application for SPC584B-DIS (different board, but same serial drivers and same RuntimeIO plugin) and the code works as expected.

/*
 * Application entry point.
 */
int main(void) {
 
  float echo = 0.0;
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  /* Application main loop.*/
  for ( ; ; ) {
    printf("Enter new parameter:\r\n");
    scanf("%f", &echo);
    printf("%f\r\n\r\n", echo);
 
    pal_lld_togglepad(PORT_E, LED_4);
    pal_lld_togglepad(PORT_A, LED_3);
    pal_lld_togglepad(PORT_D, LED_5);
  }
}

In particular, if the comma is used to separate the integer part to the decimal part when the float is inserted, the output is correct as you can verify from the following image.

Regards,

Luigi

0693W000007ZXrzQAG.jpg

View solution in original post

2 REPLIES 2
zambrano.luigi
Senior III

Hi,

I have developed a simple application for SPC584B-DIS (different board, but same serial drivers and same RuntimeIO plugin) and the code works as expected.

/*
 * Application entry point.
 */
int main(void) {
 
  float echo = 0.0;
 
  /* Initialization of all the imported components in the order specified in
     the application wizard. The function is generated automatically.*/
  componentsInit();
 
  /* Enable Interrupts */
  irqIsrEnable();
 
  /* Application main loop.*/
  for ( ; ; ) {
    printf("Enter new parameter:\r\n");
    scanf("%f", &echo);
    printf("%f\r\n\r\n", echo);
 
    pal_lld_togglepad(PORT_E, LED_4);
    pal_lld_togglepad(PORT_A, LED_3);
    pal_lld_togglepad(PORT_D, LED_5);
  }
}

In particular, if the comma is used to separate the integer part to the decimal part when the float is inserted, the output is correct as you can verify from the following image.

Regards,

Luigi

0693W000007ZXrzQAG.jpg

Bastien1
Associate III

Hi,

Thank you very much Luigi it works now !

respectfully,

Bastien