RS232 transmission format

Hi

I've got a Arduino Due and an GRATTEN ATF20B+ function generator. My goal is that i can control the function generator over RS232 with the Arduino Due. I've already implemented a levelshifter from 3,3 to RS232 levels. But im struggeling. It seems that the transmission format for the function generator is special and cannot handled by a simple Serial.write();

According to datasheet of the function generator:
"Each transmission frame consists of 11 bits: 1 start bit (logic "0"), 8 data bits (ASCII code), 1 index bit (address logic ="1", data logic ="0"), 1 stop bit (logic "1")."

I tired with this code:

byte cData[100];
int nBytesAvail = 0;
int nBytes = 0;

void setup() {
Serial.begin(115200);
Serial1.begin(115200);
Serial.println("start");

}

void loop(){
if ((nBytesAvail = Serial1.available())>0)
{
nBytes = Serial1.readBytes(cData, nBytesAvail);
Serial.write(cData, nBytes);
}
if ((nBytesAvail = Serial.available())>0)
{
nBytes = Serial.readBytes(cData, nBytesAvail);
Serial1.write(cData, nBytes);
}
}

Unfortunately it doesn't work. I need to send a special command over RS232 to enter full access of the function generator. Here the link to the function generator datasheet. I set the function generator to adress 1 and set it to 115200baud. then sending with the code above 1RS232 command to enter the full RS232 mode. But nothing happens.

In my understanding now i need to access a bit level instead of a byte level so i can set the bits right.

It would me make very happy if you could assist me in this.

ATF20B_User_Manual.pdf (668 KB)

See Serial.begin().
I think the problem is rather in the "config" part, there is no configuration for 11 bit frame

opto96:
According to datasheet of the function generator:
"Each transmission frame consists of 11 bits: 1 start bit (logic "0"), 8 data bits (ASCII code), 1 index bit (address logic ="1", data logic ="0"), 1 stop bit (logic "1")."

Reading this description it sounds likes it used 9-bit serial where the actual transmitted data is 9 bits long. I think here bits 8-1 would be the data bits and bit 0 the index bit but it may well be the other way round!

so your transmitted data should look something like this IMHO should you use 9 bit serial as above:

uint16_t tx_data = ((uint16_t)data_bits << 1) | index_bit;

I've have myself tinkered a bit with 9 bit serial

hope that helps....

opto96:
I've already implemented a levelshifter from 3,3 to RS232 levels.

are RS-232 voltages inverted? RS-232 voltage levels

opto96:
the function generator to adress 1 and set it to 115200baud. then sending with the code above 1RS232 command to enter the full RS232 mode. But nothing happens.

what do you mean by "address 1" and "1RS232"?

sherzaad:
Reading this description it sounds likes it used 9-bit serial where the actual transmitted data is 9 bits long. I think here bits 8-1 would be the data bits and bit 0 the index bit but it may well be the other way round!

RS-232 is LSB first, so bit 9 is indeed the last bit out if you are working in 9-bit mode.

So it would seem you need at least...

Serialx.begin(9600, SERIAL_9N1);

...as detailed by sherzaad's post.

And also gcjr is correct. RS-233 logic levels are inverted from TTL:
TTL 0V = +3V to +15V RS232
TTL 5V/3.3V = -3V to -15V RS232

sherzaad:
Reading this description it sounds likes it used 9-bit serial where the actual transmitted data is 9 bits long. I think here bits 8-1 would be the data bits and bit 0 the index bit but it may well be the other way round!

pcbbc:
RS-232 is LSB first, so bit 8 is indeed the last bit out if you are working in 9-bit mode.

so it is the other way round then!

Data to be transmitted would have be formatted this way then

uint16_t tx_data = ( (uint16_t)index_bit << 8 ) | data_bits;

Thank you for all your advice.

1RS232 means that the adress of the device is 1 and the RS232 stands for the command to enter the RS232 mode. See manual. The adress is set by the device(function generator).

The levelshifter is a MAX3232 from 3,3V to RS-Level

I think its 8bit data than the 9bit the index bit.

I tried to include to the HardwareSerial.h but i failed. For some reason it threw errors but its pretty standard procedure and i do not know where i made the fault.

I tried this instead in the setup routine:

index_bit=1;
data_bits = 1;
uint16_t tx_data = ((uint16_t)data_bits << 1) | index_bit;
Serial1.write(tx_data);
index_bit=0;
data_bits = 'R';
tx_data = ((uint16_t)data_bits << 1) | index_bit;
Serial1.write(tx_data);

... so on, to full command 1RS232

But it didn't work. The Function generator didnt enter the rs-mode

I must clearly missing something, if you could help me further it would be nice. thank you.

Did you have a look at the SERIAL_8E2, SERIAL_8N2 (e.g. Serial.begin(115200,SERIAL_8N2); )? If you do it right you can set the parity bit correctly for the 1 index bit (address logic ="1", datalogic ="0"). Also, be aware that the RS232 signal must be inverted to get the right TTL input. I am currently writing a RS232 monitor device and it took me a while before I was aware of this. Because I only need the input of the RS232 TX signals I use a NPN transistor to invert the signal. The MAX3232 is of course a better option if you also want also to transmit the signal.

I see it like this:

1 Step. Get this special libarary running. [Solved] 9 bit serial problem - Programming Questions - Arduino Forum
For that i need to replace the .h and .cpp files where the orignials where located. I didnt had success yet. I've found out i have multiple locations.

2 Step. Tinker a round with SERIAL_9N1. Cross fingers and hop to get it running in a within a useful period.

have you tried connecting a laptop to your device and sending it commands using a usb/rs-232 adapter?

Yes i tried an usb-rs232 adapter. i can enter the rs232 mode with 8N1. But afterwards no reaction to any commands what so ever. It may need after the rs232 mode entered the 9N1 mode. which would be strange? i really dont know yet.

Therefore im guessing that the library which sherzaad wrote, 9bit-serial, doesent work on Arduino Due. Because its throwing tons of warnings and errors.

Like:

In file included from C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:38:0,

from C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:201,

from sketch\atf20b.ino.cpp:1:

C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/UARTClass.h:28:0: warning: "SERIAL_8N1" redefined [enabled by default]

#define SERIAL_8N1 UARTClass::Mode_8N1

or:

Q:\F_E\04_Infrastruktur_Projekte\4110_TEFLAB\20_Elektronik\20_SW\Arduino\ScriptsExamples\ATF\atf20b\atf20b.ino: In function 'void setup()':

atf20b:12:32: error: call of overloaded 'begin(int, int)' is ambiguous

Serial1.begin(115200,SERIAL_9N1);

^

***********************************************20_SW\Arduino\ScriptsExamples\ATF\atf20b\atf20b.ino:12:32: note: candidates are:

In file included from C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\variants\arduino_due_x/variant.h:39:0,

from C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:201,

from sketch\atf20b.ino.cpp:1:

C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USARTClass.h:111:10: note: void USARTClass::begin(uint32_t, USARTClass::USARTModes)

void begin(const uint32_t dwBaudRate, const USARTModes config);

^

C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USARTClass.h:111:10: note: no known conversion for argument 2 from 'int' to 'USARTClass::USARTModes'

C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USARTClass.h:112:10: note: void USARTClass::begin(uint32_t, UARTClass::UARTModes)

void begin(const uint32_t dwBaudRate, const UARTModes config);

^

C:\Users\dasc\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/USARTClass.h:112:10: note: no known conversion for argument 2 from 'int' to 'UARTClass::UARTModes'

exit status 1
call of overloaded 'begin(int, int)' is ambiguous

opto96:
....Therefore im guessing that the library which sherzaad wrote, 9bit-serial, doesent work on Arduino Due. Because its throwing tons of warnings and errors.

You're right, the library I modified unfortunately does not support the Due....

You do however still have the option of trying 9-bit software serial libraries like this one...

hope the helps...

Thank you for your reply. Good to know.

I can change settings in the Function generator now. But i didnt found the output command yet.

Termite 3.4, the Serial-USB-Rs232 pc programm says 8N1. very strange. But at least its working a little for now and i have to figure more of the commands out.

BUT still, the next step would be to get it running with Arduino Due and MAX3232, not this USB-PC-RS232

Can anyone please download the manual in the first post and look up the commands?

Because this isnt working 1CHA:SWITCH

I can change frequency which is enough for now but i cannot switch it on. All i need is to switch the output on like a simple push of a button.

still over usb-rs232.

thank you

opto96:
Because this isnt working 1CHA:SWITCH

before that did you try the examples on page 29 of the manual?

Example1:
Channel A, Single output, Sine wave, Frequency 1MHz
RS232 mode, address 88:

88CHA:AWAVE:0:No.
88CHA:AFREQ:1:MHz

mentioning just one of the examples here but did any work?!

Protocoll:

1CHA:AWAVE:0:No.
01
1CHA:AFREQ:1:MHz
01

01 is the response of the function generator. meaning all good and understood. in case of a not correct command ther is FF. But how do i turn the output on. I mean it changes the frequency and that i see on the screen of the function generator but there must be a proper command to turn output on. All your recommended commands did is setting it but not turning it on. That do i know for sure because i connected the output of the function generator with a oscilloscope. And no turning on of the LED in the function generator wich says "output/Trigger"

any further recommendations?

This manual is so poorly documentated. I found a command which isn't documented. Commands so far:

1RS232 //REMOTE COMMAND MODE
1LOCAL //END REMOTE COMMAND MODE

1CHA:AFREQ:1:MHz //Frequency

1CHA:AOFFS:1:Vdc //Offset

1CHA:AMP:4:Vpp //Peakpeak-Amplitude

1CHA:AWAVE:01:No. //Squarewave

I'm still missing the relais/output/trigger command. any ideas?

opto96:
I'm still missing the relais/output/trigger command. any ideas?

try contacting the manufacturer! this is no longer a programming OR arduino related question!

the main issue is still open. how to write from arduino to function generator. so i will come back to this topic for shure.

over usb-rs232 and termite 3.4 tool it works but not with arduinoDue-max3232. there must be a code which im missing. i tried a lot but nothing helped. according to manual you have to end the string with linefeed. which i tried. also with \r.

char s[8] = {'1', 'R', 'S', '2', '3', '2', '\r', '\n'};

Serial1.print(s);

and yes it sends correctly, i connected the max3232 output with the usb-rs232 module and i see clearly the correct text in the termite 3.4 tool on the computer.

any ideas?