Show Posts
Pages: [1] 2
1  Using Arduino / Networking, Protocols, and Devices / Re: Understanding Serial write sending data bigger than buffer size¸ on: November 11, 2013, 03:58:57 pm
Dear Sir,

thank you for the answer.
So if I understand correctly, even if i call serial write 1000 times - when the outgoing buffer gets filled, the serial.write will wait until the buffer is free and only then new data will be written to the buffer? But the rest of the code will execute nevertheless?
What if the next loop iteration occurs before the data gets sent?
If the buffer cannot get overflowed then the only explanation is that the code stops executing until all the bytes are sent?
Please help me understand,sinc you can see i am a bit slow to catch up...

Thank you and best regards,
K
2  Using Arduino / Networking, Protocols, and Devices / Re: Understanding Serial write sending data bigger than buffer size¸ on: November 08, 2013, 04:14:16 pm
Dear Sir,

thank you very much for your exhaustive answer (s)!

I will try your suggestions.

One more question please: if I define the buffer size (not the Tx and Rx individually, but the one defined in the original HardwareSerial.cpp!), does that mean that this size is allocated for both the Tx and Rx buffer?

Thank you again and best regards,
K
3  Using Arduino / Networking, Protocols, and Devices / Re: Understanding Serial write sending data bigger than buffer size on: November 08, 2013, 01:34:30 am
Hello,

thank you very much for the quick answer and explanation.

Code:
int16_t some_data[150];
Thats 300 bytes of data!!

I honestly meant an 8bit datatype, sorry for the mistake. smiley

What are the problems if I don't use the power of 2 for the serial buffer size? My problem is that my SRAM is quite full (~70%) and changing the buffer size to 128 bytes fills it up to ~85%, 256 bytes to 98%. Even 85% seems high to me, but this should work without problems, I think.

Is it possible to increase the Tx buffer size an Rx buffer size individually?  

I will try using the 128 bytes buffer and reading faster from the port and see what will happen. Do you know at what rate does the processor fill the data into the output buffer if the is no manual delay? For example if I send 30 bytes of data, and don't read them, how fast will the buffer fill up?

Thank you again and best regards,
K
4  Using Arduino / Networking, Protocols, and Devices / Understanding Serial write sending data bigger than buffer size¸ on: November 07, 2013, 01:48:04 pm
Hello,

I would like to ask a question regarding the atmega328p's serial output buffer. I want to send for example 150 bytes of data over the serial port and read the data on the other end (PC), where I am reading the data sent every 5 ms.

The relevant code on the uC:

Code:
int16_t some_data[150];

void setup() {
Serial.begin(115200);
}

void loop() {

uint8_t* pD = (uint8_t*) &some_data[0];

for(int16_t i = 0;i<150;i++,pD++) {
Serial.write(*pD);
}
}

Is it possible to write the data to the serial port like this? Since there is no delay, will this overflow the buffer? Because, sometimes I get the data ok, but sometimes the data seems to be corrupt.

Do you have any advice on this?Can I increase the buffer size of the chip by changing the HardwareSerial.cpp?I am uploading my code through ICSP without the bootloader. Should I sent the data in three packets with a delay between like so:

Code:
int16_t some_data[150];

void setup() {
Serial.begin(115200);
}

void loop() {

uint8_t* pD = (uint8_t*) &some_data[0];

for(int16_t i = 0;i<64;i++,pD++) {
Serial.write(*pD);
}

pD++;
delay(some_delay);

for(int16_t i = 0;i<64;i++,pD++) {
Serial.write(*pD);
}

pD++;
delay(some_delay);

for(int16_t i = 0;i<22;i++,pD++) {
Serial.write(*pD);
}
}

Any other thoughts? Any help would be much appreciated.

Thank you and best regards,
K
5  Using Arduino / Networking, Protocols, and Devices / Re: CRC generator (polynom) selection on: October 21, 2013, 12:52:30 pm
Thank you very much for your answer.

But I am a little confused right now... I thought that the receiver end determines the size of the buffer? For example, if I establish a serial connection between Arduino (transmiter) and PC (receiver) and read the data, isn't the buffer size limited by the receiver buffer?
I am asking this, because I have been sending ~130 bytes of data and had no problem reading this. My loop was executing every 15 ms and I was reading the serial port on the PC as fast as I could. As far as I analyzed the data, there was no loss. Probably, I was reading the data fast enough?

I would like to keep the same method of communication.

Thank you and best regards,
K
6  Using Arduino / Networking, Protocols, and Devices / CRC generator (polynom) selection on: October 21, 2013, 06:55:51 am
Hello,

I am trying to implement CRC checking for data over serial and have been reading some papers regarding the proper polynomial selection. I have read the "Cyclic Redundancy Code (CRC) Polynomial Selection For Embedded Networks, Koopman P." paper, where the "good" polynomials are described. One thing about this paper that is causing me problems is that the maximum tested data length was 2048 bits.

I need to implement a good CRC for an interval of 4 bytes to 600 bytes. I have been testing the CRC-16 (modbus) algorithm with (0xA001).
I have been searching for some advice on how to select the proper polynomial and CRC for my data size, but have been unsuccessful so far. Should I use CRC-8 for shorter data and CRC-16 for longer data?

Any suggestions please? I would also be grateful if some paper or similar could be cited regarding my question.

Thank you and best regards,
K
7  Using Arduino / Networking, Protocols, and Devices / Re: Serial read on: October 20, 2013, 06:24:50 am
Dear Mr. Gammon,

thank you very much for the answer. I will read the link you have provided with great interest.

Best regards,
K
8  Using Arduino / Networking, Protocols, and Devices / Serial read on: October 18, 2013, 01:14:16 am
Hello,

I would be very grateful if somebody could explain the following outcome of the serial communication.

I am using some global variables (datatype char and byte) to make decisions in the "loop" part of the code. The variables get modified over the serial input buffer, where I read 2 bytes and act accordingly (please see the code below)

Code:
while(Serial.available() > 1) { // wait for 2 bytes
  // prefix command
  prefix_command = (char) Serial.read();  

  if(prefix_command == 'r') {
  command_r = (char) Serial.read();  
  }

  else if(prefix_command == 'f') {
  command_f = (char) Serial.read();    
  }

  else if(prefix_command == 'E') {
  eeprom_data = (byte) Serial.read();
  }

  else Serial.println("ERROR");  
  }

If I open the serial monitor and send two bytes of data (ascii format), for example r0, the first "if" condition is met and the "command_r" is modified to '0'. This works for all modes and I have no problem here.

The question I have follows: If I send two bytes of data, the values get modified, but not before the "ERROR" is printed out. Why is this happening? It may be very obvious, but I really can't tell.

Also I will be trying to implement CRC checking for my data over the serial, sending ~100 bytes (so CRC-16 should be okay right?). Do you have any pointers about calculating the CRC checksum? Are there any tested (optimized) libraries that could be used with arduino (basically I have a custom board with Atmega 328p)?

Thank you very much and best regards,
K

9  Using Arduino / Programming Questions / Re: Serial event on: June 21, 2013, 01:22:01 am
Thank you for all your help.

It seems my mistake was in the function name SerialEvent() instead of serialEvent().

I have a sensor attached to a custom board (Atmega328p-au) and I need to change what it returns based on a serial receive command.
It works fine now.

About using while loop - I followed the example from http://arduino.cc/en/Tutorial/SerialEvent.
I removed the while loop and it works the same.

Best regards,
K
10  Using Arduino / Programming Questions / Serial event on: June 20, 2013, 12:54:18 pm
Hello,

I would like to ask a question regarding the SerialEvent() function. Looking at the following code:

Code:
char data_in; // global variable


void setup() {
Serial.begin(115200);
data_in = 'r'; // initialize default
}

void loop() {
if(data_in == 'r') {
Serial.print("something1")
}

else if (data_in == 't') {
Serial.print("something2")

}

else Serial.print("something3")

}

void SerialEvent() {
while(Serial.available()) {
data_in = (char) Serial.read();
}
}

I am wondering if this is correct? I am trying to use different parts of code with respect to what I send via the receive port.

So if I send a char 't' via the serial port, the "else if" should execute constantly until I send a diffrent char. If I write the serial data to data_in variable, will it initialize to the value I have sent over the serial (and stay the same in all subsequent iterations until I change the value)?

I am having some problems with this code, since the value I send via the serial event doesn't change (the data_in part).

Thank you for your help and best regards,
K
11  Using Arduino / Microcontrollers / Re: Using ICSP to upload hex on standalone atmega328p-au on: June 14, 2013, 01:06:00 am
Hello,

I figured it out. It was my error, the board is ok. I had my pins mixed up.

Also, when programming the standalone board, I had to manually determine which processor pin corresponds to Arduino pins initialization.

Thank you for all your help, I really appreciate the responsiveness of experts on this forum. Keep it up.

Best regards,
12  Using Arduino / Microcontrollers / Re: Using ICSP to upload hex on standalone atmega328p-au on: June 13, 2013, 12:32:27 am
Hello,

so I tried burning the bootloader to Arduino Nano (328p-au) using Arduino Uno as ISP and then also uploading a sketch to Nano with "Upload using a programmer" option (please see image below).

Everything works as expected, so no problems here.

When I try to do the same with my custom board (328p-au), I can burn bootloader just fine and also the sketch (no errors), but it is not working as expected. The only difference is that my board has 10k pullup on RESET and the Arduino Nano has only 1k. Otherwise, everything is connected ok (I have checked all the connections).
This shouldn't be a problem, right? I'm just trying to rule out this. I already think the problem is in my board design.

Thank you and best regards,
K
13  Using Arduino / Microcontrollers / Re: Using ICSP to upload hex on standalone atmega328p-au on: June 10, 2013, 08:44:32 am
Thank you kindly for your help and explanation!
Exactly what I needed!

Best regards,
K
14  Using Arduino / Microcontrollers / Re: Using ICSP to upload hex on standalone atmega328p-au on: June 10, 2013, 07:59:53 am
Thank you very much for your prompt answer. I really appreciate your help.

I already have onboard TTL to RS232  converter and I will be programing the chip only through ICSP.
I just need serial input and output to send data over to the/and from computer.

This should work right?

Best regards,
K
15  Using Arduino / Microcontrollers / Using ICSP to upload hex on standalone atmega328p-au on: June 10, 2013, 01:11:14 am
Dear all,

I really need some help please.

I am aware (thought I did not try it yet) that it is possible to program a standalone atmega (atmega328p-au) via ICSP by uploading the arduino booltloader and then uploading the sketch.

I was wondering if it is possible to upload only the sketch (hex file) and use the funcionalities of the Arduino libraries? So if i upload the hex file generated from compiling the arduino code via the icsp, will it work (particulary interested in serial comunication, Tx and Rx pin).

Thank you for your help  and best regards,

K
Pages: [1] 2