Pages: 1 [2]   Go Down
Author Topic: Visual C# and Arduino, Arduino freezes after receiving serial data  (Read 1287 times)
0 Members and 1 Guest are viewing this topic.
East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 90
Posts: 3523
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: March 14, 2013, 08:05:23 am by bamboosam » Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11197
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I get no response when:

Code:
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:

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: March 14, 2013, 10:18:29 am by bamboosam » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 68
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:

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.
Logged

Pages: 1 [2]   Go Up
Jump to: