Serial write reset problem

Hi,

I found a line of code that causes a reset problem, (doh it doesn't always reset when executing this line, it doesn't reset when I comment it). The place were it resets is random, so it's not like it reset when this line is executed, all I know is that it doesn't reset with these lines gone (very strange).


Reset causing code:

Serial.write(nul);

the null is declared by:

char nul = 0x00;

Is there anyone who knows how to replace this code, so it still writes the same thing?

Tried already:

Serial.print(0x00);         //write(int) ambigious
Serial.print(0x00,HEX);     //wrong values for 0
Serial.print(0,DEC);        //wrong values for 0
Serial.write(null);         // Not declared

What are you sending the NULL to? What does the rest of your code look like?

The null is actually used as part of an adress. I'm using XBee modules. These require a frame adress for communication. I put my code in the attachement. The following part is used as adress:

 Serial.write("    Send to Router    "); //Debugging
                        
                        //Answer - on First Recieve
                        
                        // 7E 00 0F 10 01 0000 0000 0000 FFFF XXXX 00 00 2B CS -> Frame 
                        // Checksum :          
                        CS = 0xFF-((0x10+0x01+0xFF+0xFF+PAN1+PAN2+0x2B)%256); //16² = 256
                        char nul = 0x00;      
  
                        Serial.write(0x7E);   //Startbyte
                        
                        Serial.write(nul);    //Lengte    
                        Serial.write(0x0F); 
                        
                        Serial.write(0x10);   //Frame type / ID
                        Serial.write(0x01); 
                        
                        Serial.write(nul);    //64-bit destination address
                        Serial.write(nul);    
                        Serial.write(nul);    
                        Serial.write(nul);    
                        Serial.write(nul);    
                        Serial.write(nul);
                        Serial.write(0xFF);
                        Serial.write(0xFF);
                                  
                        Serial.write(AdressArray [FIO] [3]);   //16-bit destination address  - PAN1       
                        Serial.write(AdressArray [FIO] [4]);   //                            - PAN2         
                        
                        Serial.write(nul);    //Extra
                        Serial.write(nul);   
                        
                        Serial.write(0x2B);   //Information
                       
                        Serial.write(CS);     //Checksum

API_test14_dec17c.ino (15.7 KB)

It looks to me like you are using the serial port to talk to the XBee and the PC, and expecting the XBee to know what you are trying to get it to broadcast vs. what it should ignore.

Life will get a lot easier when you stop doing that.

When the debugging is finished, I was planning to remove all the extra serial writes, but I don't think that this is what causes the reset or is it? do you know another way for sending en HEX value of 00 in my adress?

MrSt0p:
When the debugging is finished, I was planning to remove all the extra serial writes, but I don't think that this is what causes the reset or is it? do you know another way for sending en HEX value of 00 in my adress?

I'd be more worried by the fact you apparently have the Arduino serial pins driven by the USB serial driver and the UART and the XBee. Each serial connection can (should) only have TWO end points. Setting up a three-way connection is asking for trouble, because you will have different output drivers fighting against each other. Perhaps one will tend to win and it will appear to work, but it's a fundamentally bad idea IMO. If your Arduino needs to talk to the PC and to an XBee module then you need a separate serial connection for each one.

The fact you're then sending binary data to the PC and debug messages to the XBee just adds insult to injury.

do you know another way for sending en HEX value of 00 in my adress?

No matter what method you use, the same 8 bits, all 0, are sent. Sending the NULL is not the problem.

Andrew Rapp wrote a nice library for using the XBees in API mode. Why aren't you using it?

I tried it, but I don't understand how it works, and I thought that if I only had to send some small values, it would be eassier like this. Never worked with libraries :s is it hard to implement? how long would it approcimatly take for someone with let's say 0 knowledge to get it to work?

Ow and also, he starts working with processing, I don't get how to go to processing. I read the book from Faludi, Robert: Buidling Wireless Sensor Networks. He also works with XBee's, and I completely understand everything until processing comes in. :s