I am building autonomous robot. I would like to use SRF01 Ultrasonic range finder that ultrasonic device to do the object avoidance. The ultra sonic trasmit data using serial TTL logic. And i know the Arduino UNO has a serial RX and TX line that TTL logic(Please correct if i am wrong).
Know my question is:
how do i write and read from these port?
does RX support Interrupt. That is when data is received does it call an interrupt which would automatically start receiving the data. If no code is written for this does the chip support such function because i want to have an Interrupt to automatically start receiving data as soon as it detect something on the RX. The reason I want this because i don't want to constantly put the Serial RX in listening mode till it get something.
I used to do alot programming on the HCS12 micro and it supported this.
Ok so i just found out about newsoftserial.
I want some to please explain something to me. The code below uses newsoftserial libary that uses interrupt. So say for example in the loop it checks for available data on the RX if there no avoidable data it continue running the code how is that an interrupt?
Because say for example the only way i can check data is if i call the ".available" function.
So say for example i write a bunch of code below my ".available" function the only time that it gonna check for data on the RX is when it calls the ". available" function
Could some explain to me how this uses interrupt because the only time i getting data is when the ".available" function is called. I want to be able to get data as soon as RX get data fill up an array and use it RIGHT AWAY.
I am guessing i gotta write my own code for this.
#include <NewSoftSerial.h>
NewSoftSerial nss(2, 3);
NewSoftSerial nss2(4, 5);
void setup()
{
nss2.begin(4800);
nss.begin(4800);
Serial.begin(115200);
}
void loop()
{
// Every 10 seconds switch from
// one serial GPS device to the other
if ((millis() / 10000) % 2 == 0)
{
if (nss.available())
{
Serial.print(nss.read(), BYTE);
}
}
else
{
if (nss2.available())
{
Serial.print(nss2.read(), BYTE);
}
}
}
Could some explain to me how this uses interrupt because the only time i getting data is when the ".available" function is called.
The newsoftserial does indeed use interrupts to handle incoming serial characters. As they come in they are stored into a 64 byte FIFO buffer and increment a received character counter. When you call .available the return value is how many characters are waiting for you to read from the buffer. So as long as your program runs .available before the possibility of more then 64 charaters having arrived you will not miss or 'drop' any characters. At 9600 baud takes about 1 millsec each character, so at that speed your sketch must be checking at least better then once every 64 millsec to see if there are any and how many characters are waiting to be read from the butter. So the interrupts handles the incoming data stream byte by byte, but your program must check .available at some time interval that will ensure you don't have a buffer overflow and drop characters.
I think the answer to your original question is Yes. The Rx & Tx lines go to a hardware UART, this will start receiving data once the code gets to Serial.begin(baudrate).
Then you use if available()to see if data is there, and value = serialRead to pull the byte out of the hardware USART.
See Section 19 of the data sheet for hardware details.
Then you use if available()to see if data is there, and value = serialRead to pull the byte out of the hardware USART.
Not true if you are using the standard Arduino serial commands. They use a core library (HardwareSerial.cpp/h) to set up a intermediate 128 byte buffer and the library handles the pulling bytes from the usart buffer into the software buffer and keep a arrived character count variable that the .available command uses. The Arduino serial receive function and the new software serial library function much the same way. The Arduino library has less to manage because of the hardware usart on chip, but it processes interrupts and stores characters into a FIFO buffer in the same manner.
if you are using the standard Arduino serial commands. They use a core library (HardwareSerial.cpp/h) to set up a intermediate 128 byte buffer and the library handles the pulling bytes from the usart buffer into the software buffer and keep a arrived character count variable that the .available command uses.
Ok i thought the standard serial command that came with Arduino were not interrupt driven?
On another note where can i find the interrupt for timers. I need to get a counter to set a FLAG every one second and i will just put the counter in one the interrupt timers but i need to know how often the timer get called. So i need to know the Prescaler and how often the timer over flows or how often the timer does an output compare.
Where can i find these files?