Clear Filters
Clear Filters

Embedded program hangs because UART transmission

4 views (last 30 days)
Hi,
I have a problem with my embedded programming with TivaC launchpad. I have a lot of blocks that include I2C acquisition for an IMU, a UART for GPS and a UART for Xbee.
The last part of the program that I made was the Xbee transmission. Before I made the Xbee block all the program runs perfectly in my launch pad, but when I made the S-function for the serial transmission I found 2 problems.
First: When I begin the program all run fine for 5-6 seconds, but sometimes it can run for 2 minutes without a problem, but in some moment the program hangs.
Second: I have an ADC input from sonar, when I test and graph without the Xbee the signal are totally plain, but when I test with Xbee sending every 3 seconds the signal from the sonar measure with a pic every time the serial was sent.
I think that with this both errors the problem is the memory managing of the launchpad, but I can't find the way to test or solve it.
This is the code of the S-function for the xbee:
/*
* Include Files
*
*/
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#include "rtwtypes.h"
#endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
# ifndef MATLAB_MEX_FILE
# include <Energia.h>
# include <math.h>
# endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Create external references here.
*
*/
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
/* extern double func(double a); */
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */
/*
* Output functions
*
*/
extern "C" void Radio_Link_Outputs_wrapper(const real_T *UART_1,
const real_T *xD,
const int_T u_width)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
if (xD[0] == 1){
# ifndef MATLAB_MEX_FILE
int as=0;
Serial4.print('$');
for (as=0;as<u_width;as=as+1){
Serial4.print(UART_1[as]);
if (as!=(u_width-1)){
Serial4.print(',');
}
}
Serial4.println('%');
# endif
}
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}
/*
* Updates function
*
*/
extern "C" void Radio_Link_Update_wrapper(const real_T *UART_1,
real_T *xD,
const int_T u_width)
{
/* %%%-SFUNWIZ_wrapper_Update_Changes_BEGIN --- EDIT HERE TO _END */
if (xD[0] != 1){
# ifndef MATLAB_MEX_FILE
Serial4.begin(57600);
# endif
xD[0] = 1;
}
/* %%%-SFUNWIZ_wrapper_Update_Changes_END --- EDIT HERE TO _BEGIN */
}
The simulink diagram of the uart section:
Do you have some idea to solve it?
Thanks

Answers (0)

Categories

Find more on Embedded Coder in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!