Arduino Forum

Products => Arduino Due => Topic started by: joeblogs on May 23, 2017, 03:48 am

Title: due 16u2 update serial garbage
Post by: joeblogs on May 23, 2017, 03:48 am
Hi
is the serial garbage fixed by downloading board upgrades through the ide, or do i have to download the older version of the ide to use with the upgrade description

https://www.arduino.cc/en/Hacking/Upgrading16U2Due (https://www.arduino.cc/en/Hacking/Upgrading16U2Due)
Title: Re: due 16u2 update serial garbage
Post by: ard_newbie on May 23, 2017, 10:29 am

AFAIK once UART is properly programmed, there is no garbage received in the serial monitor.

Title: Re: due 16u2 update serial garbage
Post by: joeblogs on May 23, 2017, 11:03 am
cheers ard
by that do you mean not to solely rely on the arduino setup is there xtra work to do ie,datasheet

this is my setup
Code: [Select]


void setup()
{
Serial.setInterruptPriority(2);
Serial.begin(115200);

Serial.flush();
SI.empty_serial_buffer(); //reads until buffer empty




this is the function out put on the serial monitor
Code: [Select]


Opening port
Port open
Choose from codes below
---------------------------------------
Code Description
X Exit without making selection
1 26 pin data recorder
2 To record pulse timing on a single pin
3 To record timing and count of a series
of pulses, on a single pin



this is the same function run a second time with further output
Code: [Select]


Choose from codes below
---------------------------------------
Code Description
X Exit without making selection
1 To use default data reco    <-----stops here sometimes garbage, sometimes not



this is what should be printing
Code: [Select]


//options for initial configure setup
int configure_opt;

const int config_choices = 2;
constexpr int config_opt[config_choices] {1, 2};

String config_opt_msg[config_choices]
{
"To use default data recorder settings", //1
"To setup with new data recorder settings" //2    <------ should be printing here
};
//end configure setup



this is the function
Code: [Select]


bool SerInput::check_for_int_input(int &dest, const int src[], const int src_size, String msg[])
{
bool ret = false;
bool print_once = true;
bool reading = true;
bool input_match = false;
int number_in = 0;
char input[10];
int input_idx = 0;

while(input_match == false)
{
//header print
if(print_once == true)
{
print_single_input_header();
print_exit_option();

for(int i = 0; i < src_size; i++)
{
//long buff_sz = Serial.availableForWrite();
//Serial.println(buff_sz);
//long tl = msg[i].length();
//Serial.println(tl);
Serial.print( src[i] ); Serial.print('\t'); Serial.println( msg[i] );
//buff_sz = Serial.availableForWrite();
//Serial.println(buff_sz);
//printf(" %s \n", "my test message");

Serial.flush();
}
print_once = false;
//delay(2500);

}

//read input
while(reading == true)
{
if(Serial.available() > 0)
{
input[input_idx] = Serial.read();

if(input[input_idx] == 'X')
{
input_match = true;
reading = false;
Serial.println("Exiting ");
break;
}

if(input[input_idx] == '\n')
{
reading = false;
break;
}

if( ++input_idx > 10 )
{
reading = false;
empty_serial_buffer();
break;
}
}
}

number_in = atoi(input);
//validate against array
for(int k = 0; k < src_size; k++)
{
if(number_in == src[k])
{
input_match = true;
ret = true;
dest = number_in;
Serial.println("Confirmed: ");
Serial.print("\t");
Serial.println(msg[k]);
break;
}

}

if(input_match == false)
{
reading = true;
input_idx = 0;
memset( input, 0, sizeof(input) );
Serial.println("Incorrect entry, choose one of the codes above");
Serial.flush();
}
}

Serial.println(header_seperator);
Serial.println();
Serial.flush();

return ret;
}




Title: Re: due 16u2 update serial garbage
Post by: ard_newbie on May 23, 2017, 11:39 am

I don't understand why you are using "Serial.setInterruptPriority(2);". It's not a good idea to modify UART interrupt priority unless you really know what you are doing.

You have a very simple example of a Serial reading from Serial monitor at:

File > Example > Communication > SerialEvent

then, depending on your Serial inputs (plus carriage return) you select the corresponding routine and you are done.

Select 250000 as Serial baud rate.
Title: Re: due 16u2 update serial garbage
Post by: joeblogs on May 23, 2017, 11:37 pm
i changed the priority because i want the pin change interrupts of the program to happen when they happen not wait for serial functions to complete.

do you use clones or genuine boards
Title: Re: due 16u2 update serial garbage
Post by: ard_newbie on May 24, 2017, 06:12 am
Hi joeblogs

attachinterrupt  in Winterrupts.h has received a major improvement done by antodom thanks to the count leading zeros assembler instruction, and AFAIK this version (except the register type) has been implemented in the latest versions. See this thread reply #106 :

https://forum.arduino.cc/index.php?topic=144446.105 (https://forum.arduino.cc/index.php?topic=144446.105)

I use clone boards too.
Title: Re: due 16u2 update serial garbage
Post by: joeblogs on May 24, 2017, 12:04 pm
cheers

i am slowly getting to the problem i think,

does any one know why the following example causes the serial monitor to not print anything at all
Code: [Select]


struct fred { const char id[3]; const char msg[64]; };     <-------- 64

struct fred x[2]
{
{ { "12" }, {"test message 1"} } ,
{ { "21" }, {"test message 2"} }
};


void PrintString(const char *str) {
const char *p = str;
//p = str;
while (*p) {
//printf(p);
Serial.print(*p);
p++;
}
Serial.println();
}




void setup()
{
Serial.begin(115200);

PrintString(x[1].id);
PrintString(x[1].msg);
}



yet if i change 64 in the first line of code to 30 it works fine.

im starting to think the garbage i was getting was an out of bounds buffer array
Title: Re: due 16u2 update serial garbage
Post by: ard_newbie on May 24, 2017, 01:41 pm

Your code works fine with 64, no garbage in Serial monitor.
Title: Re: due 16u2 update serial garbage
Post by: joeblogs on May 24, 2017, 02:15 pm
cheers ard
just for a laugh, i removed the file from the project, and then added it again, rebuilt it, 2 day problem solved
(using AS7)

out of interest whats your IDE preference
Title: Re: due 16u2 update serial garbage
Post by: joeblogs on May 24, 2017, 02:47 pm
and some stupid twat left an array initialized at 7500 which worked fine until storing const strings :o