I am searching for a serial library which can use non-standard bit rates, e.g. 19304 bit/s on a digital port. In fact I just only need to send at this speed with no start and stop bits - just one byte after another. I am not new to programing but new to Arduino and microcontrollers, so I hope someone can give me a hint where I can find such a library or how to set up such functions (I think with timers an interrupts, or?)

Thanks, Holger

Perl is the only language that looks the same before and after RSA encryption.

It sounds like you are talking about synchronous communication - no start or stop bits. If that is the case, you can use the SPI function of the processor. For a 16MHz processor, you would set the baud rate register to 413 to get the baud rate you are looking for.Read the Atmel328 data sheet topic about the USART in SPI mode.

It looks like the SPI library will do what you are looking for but you'll have to modify the source for your custom baud rate.

Do you plan to use NewSoftSerial with an on chip UART or with digital pins? If you don't have a hardware UART, and you're working with sync data, you're going to be banging your head against the wall. Its easy enough to make it move data, but as soon as you try to do something with that data at the same time, its gets frustrating.

no UART :-)I need to generate a signal for driving digital modell locomotives (not DCC but Motorola-Märklin). So my other end of the communication is a decoder chip inside the locomotive. I have a rough manual how to generate the frames with a serial line at 19200 bit/s but you have to do some strange timing things to get the right signal. I thaught that it is better to generate the signal without that strange things but for this you "might" have to send the frames with a non-standard bit rate (s. http://modell-zug.com/Support/HowToArticles/DigCtrlSys/DigitalTransmission.htm). I read some documentation where they don't use exactly 4800 bit/s... but I'm not sure.

Regards, Holger

Perl is the only language that looks the same before and after RSA encryption.

It sounds like you are talking about synchronous communication - no start or stop bits. If that is the case, you can use the SPI function of the processor.

The Arduino hardware SPI is limited to a fixed set of frequencies derived from the processor clock divided by powers of two. Successive bytes may not be bit-synchronous with each other - you'd have to test that.

To generate an accurate fixed frequency the use of timer1 (which has 16bit precision) is a possible way - using a timer interrupt would be the most accurate way to use that timer to push bits out.

However the UART is probably the simplest way (if you can configure 0 start bits and 0 stop bits?)

no UART :-)I need to generate a signal for driving digital modell locomotives (not DCC but Motorola-Märklin). So my other end of the communication is a decoder chip inside the locomotive. I have a rough manual how to generate the frames with a serial line at 19200 bit/s but you have to do some strange timing things to get the right signal. I thaught that it is better to generate the signal without that strange things but for this you "might" have to send the frames with a non-standard bit rate (s. http://modell-zug.com/Support/HowToArticles/DigCtrlSys/DigitalTransmission.htm). I read some documentation where they don't use exactly 4800 bit/s... but I'm not sure.

Regards, Holger

Which Arduino are you using? You should be able to do this with a bunch of them. For example, the 324/644/1284 chip should be able to do this nicely with its onboard USART. These USARTs can do quite a bit more then the arduino code allows as is, but its very easy to hack the code to set up the USART as you need it. If you look at the HardwareSerial.cpp begin() method, you'll see that there is not too much to it.

I took a look at the data sheet for the system you are trying to simulate and I don't think a USART is going to do the job. The Motorola decoder expects a "binary-encoded trinary" signal with two different bit times, not the uniform bit times that conventional USARTs use. You could probably modify SoftwareSerial to accomplish what you're after.

@MarkT: I hoped to find a way to avoid writing the interrupt driven code :-) but it seems that I have to write such library (which will take more time for me than I thaught). My problem is that I have no scope, so I have to do trial & error for the signal generation (that's a problem with all other solutions, too).

@Bill_Kerr: Yes, that's also a possibility to avoid the software signal generation code. But I know that there is a working(!) software implementation based on UARTs (http://srcpd.sourceforge.net/srcpd/index.html). I will keep in mind to change to the hardware signal generation when everything will fail.

@skyjumper: I will use the the Arduino UNO (328P). It seems that someone has made a Port from OpenDCC to the Arduino (http://developer.berlios.de/projects/microsrcp/) which is also based on UART output (like srcpd). But I hope to get arround the tricky timings when using the "right" bit rate to communicate with.

It seems that I have to write my own signal generation code with interrupts or I have to use the hardware encoder from Motorola...

Regards, Holger

Perl is the only language that looks the same before and after RSA encryption.