Go Down

Topic: Visual C# and Arduino, Arduino freezes after receiving serial data (Read 1 time) previous topic - next topic

UKHeliBob

Quote
When you send data using serialport1.WriteLine(), it always sends a '/n' at the end.
It doesn't send an '/n' if you just use serialport1.Write()

Yes, but where do the 5 and 12 come from that you say you are sending ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

bamboosam


Quote
When you send data using serialport1.WriteLine(), it always sends a '/n' at the end.
It doesn't send an '/n' if you just use serialport1.Write()

Yes, but where do the 5 and 12 come from that you say you are sending ?


I was literally sending '5' and '12' from Visual C#. Random numbers I chose, one of which I wanted to have 2 digits.

bamboosam

#17
Mar 14, 2013, 02:03 pm Last Edit: Mar 14, 2013, 02:05 pm by bamboosam Reason: 1
My setup is a little strange.

Using a macbook pro and windows VMware

Breadboard - 1284p, ftdi breakout (sparkfun), AVR MKII
Maniac Bug's - Mighty 1284p 16MHz using optiboot
Running arduino 1.0.3 on mac side
Running Visual C# on windows side

I program the 1284p with the AVR MKII - "Upload using programmer" (because I could never get the ftdi to program the 1284p)
ftdi is connected to the windows side

So, I can't use arduino's serial monitor. The AVR MKII isn't serial, so I have nothing to communicate with it on the mac side/arduino IDE.

I've read that the 1284p DIP package has real issues with the ftdi, programming it at least. So that could be the red flag. I've never been able to program it using that. I have pcb's for the 1284p-AU package, I will solder jumpers to the rx0 and tx0 pins and see if I have better luck.

Is it necessary that I have FTDI DTR tied to reset pin?

PeterH


I get no response when:

Code: [Select]
if ( c != '\n' || c != '\r')

How to I check if the input buffer is full?


You know the buffer is full when your index variable equals the length of the buffer.

Your logic checking for end-of-line is a bit tortuous because you're checking for characters NOT being end of line, so in that case you would need to use 'and' rather than' not. It would be much simplrer if you inverted the logic like this:

Code: [Select]


const int MAX_LEN = 20;
char buffer[MAX_LEN+1]; // allow space for the terminating null
int length = 0;
...

if ( c == '\n' || c == '\r')
{
  // end-of-line received
  // process content of buffer, if any
  if(length > 0)
  {
     handle(buffer);
     length = 0;
  }
}
else
{
  // not end-of-line
  if(length < MAX_LEN)
  {
    buffer[length++] = c;
    buffer[length] = '\0';
  }
}


You'll notice I renamed 'i' to 'length'; it's common to use single letter variables as local loop counters and your global 'i' would clash with any local variables of the same name.
I only provide help via the forum - please do not contact me for private consultancy.

bamboosam

#19
Mar 14, 2013, 03:54 pm Last Edit: Mar 14, 2013, 04:18 pm by bamboosam Reason: 1
Ok I managed to get jumper wires soldered to the tx0 and rx0 pins on a1284p-AU package, and... It works perfectly. Not a miss, consistent every time.
I am extremely relieved because that was driving me nuts, I knew I must have been doing it right at some point, and I am absolutely sure I have my breadboard 1284p DIP setup correctly.

So it is definitely something with the 1284p DIP package's tx0 and rx0 pins internally interfering with each other, so watch out.

Thank you guys for the help, I really appreciate it.

bamboosam

Quote

Code: [Select]


const int MAX_LEN = 20;
char buffer[MAX_LEN+1]; // allow space for the terminating null
int length = 0;
...

if ( c == '\n' || c == '\r')
{
 // end-of-line received
 // process content of buffer, if any
 if(length > 0)
 {
    handle(buffer);
    length = 0;
 }
}
else
{
 // not end-of-line
 if(length < MAX_LEN)
 {
   buffer[length++] = c;
   buffer[length] = '\0';
 }
}


You'll notice I renamed 'i' to 'length'; it's common to use single letter variables as local loop counters and your global 'i' would clash with any local variables of the same name.


Thank you, I will do that.

Go Up