The input data will never get close to filling all of that up. It nearly is, because it is a 32K * 8 SRAM. You can assume for the purposes of the Pseudocode above that the RAM storage into which the received characters is being placed is limitless. Begin working through the RAM from address 0 and processing the received data Re-load HardwareTimer with uiTimeOutValueĪll data now received. Receive and store it in RAM location 'uiAddress' If there is a serial byte waiting to be received Load hardware timer 'HardwareTimer' with value equivalent to uiTimeOutValue // (assume it is a downcounter) Read serial input bytes until 'start' character is received. If I were going direct to the hardware on Arduino or on any other processor like a PIC I would do something like: (Pseudocode) If no more appear to be coming, then the receive phase of the operation ends The only thing which makes the last character unique is that it will not be followed by any more characters, so I want to determine that by timing the interval since the last character was received. I want to do it this way because the material being received contains no information about its length / size and no special 'end of stream' marker character - the final byte of incoming information is equally likely to have any value from 0x00 to 0XFF. If the time since the last received byte exceeds that set interval, that is how the code determines that the sender is not going to send any more. Once the start character has been detected the code then needs to carry on receiving single raw bytes for as long as they continue to arrive within a set time interval. The code will initially look forever for the 'start' character and if it receives any other character in the meantime then it will discard that character and carry on looking for the start character. Even if there are more in the buffer, it only reads one at a time. Just ignore the comments at the top of the program.In the scenario described, the code is receiving single raw bytes one at a time. If it does you might try a higher value resistor such as 5600. AFAIK the presence of the resistor will not interfere with genuine serial data. The reason for connecting to 5v (rather than GND) is because the serial system normally idles HIGH. And I think that would be a suitable solution for you. When I connected Rx2 to the 5v pin via a 4700 ohm resistor the input from Serial2 ceased. This led me to think that the input pin for Rx2 is floating and creating spurious values. That continues even after I remove the piece of wire. When I stick a piece of wire into the socket of pin 17 (Rx2) it starts showing 63 characters in the buffer and showing a value of -1 in the variable rec. When I re-start the Mega nothing appears from Serial2. get the first two bytes and convert to an int board, arduino:avr:mega:cpu=atmega2560 I have just tried this program on my Mega // python-build-start Serial.println("something came through") put your setup code here, to run once: When using this, it would just go into the function and stay there. It is my understanding, if nothing is being sent, then serial.available returns 0 and therefore doesnt satisfy the loop conditions. This works, but my problem is, if nothing is being sent by the mini - or even if I pull out the rx tx connections, somehow the code still goes into the serial.available() loop, and it says that the incoming byte is 0. My mega sends a signal to the mini to get the mini to send back 'T' to the mega via serial. Im trying to connect a mega adk, and a pro mini together with txrx.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |