SoftwareSerial library

Hi all, i'm trying to communicate with an old device that has to read each 15Khz 6 bytes. Communication set up has 8 data bits+one bit of even parity+one stop bit. I discovered softwareserial, but i dont know how to calculate new " // baud rxcenter rxintra rxstop tx". Does anybody know how to do it? and should 960 baud for 15khz?? Thanks in advance, i'm lost :(

SoftwareSerial.begin(9600); //Initialize the software serial port.

If that helps.

Thanks, i read the library .cpp and problem is that 960 bauds is not used, i mean:

#if F_CPU == 16000000

static const DELAY_TABLE PROGMEM table[] = 
{
  //  baud    rxcenter   rxintra    rxstop    tx
  { 115200,   1,         17,        17,       12,    },
  { 57600,    10,        37,        37,       33,    },
  { 38400,    25,        57,        57,       54,    },
  { 31250,    31,        70,        70,       68,    },
  { 28800,    34,        77,        77,       74,    },
  { 19200,    54,        117,       117,      114,   },
  { 14400,    74,        156,       156,      153,   },
  { 9600,     114,       236,       236,      233,   },
  { 4800,     233,       474,       474,      471,   },
  { 2400,     471,       950,       950,      947,   },
  { 1200,     947,       1902,      1902,     1899,  },
  { 300,      3804,      7617,      7617,     7614,  },
};

These are bauds to work (most used). Thanks,

Any idea?!?

that has to read each 15Khz 6 bytes

Can you explain what that means, and where 960 bits per second comes into it?

Sorry for my bad explanation =(; i will detail what i have to do. I have to communicate with an old device (really old, more than 20 years with no chance to change anything on it). This device has to receive 6 bytes to work. The device that was communicating with it, now is dead (r.i.p.) and is impossible to replace it, so i have to make something new, and this is why i'm posting this. Device that now is dead (r.i.p.) worked with a serial transmission, each 15625Hz sent 6 bytes + parity bit + stop bit, with a speed of 1/8Mhz (crystal) per instruction. This is sent each second. I found SoftwareSerial and thought that could work. Thanks for the help,

each 15625Hz sent 6 bytes + parity bit + stop bit

That still doesn’t make a lot of sense.
Are you saying that every 64 microseconds you have to send 66 bits of data?(I assumed you’d forgotten about the start bit)
Or that you have to send the 66 bits of data in 64 microseconds, but only once a second?
Or that there’s a single stop bit and a single parity bit for all 48 bits of data? (in which case receiver margins will be very tight)

I still don’t see where the 960 comes into this.

Why do you need to use software serial, and not the hardware USART?

That still doesn't make a lot of sense.

Sorry for that, i don't explain well.

Are you saying that every 64 microseconds you have to send 66 bits of data?

Yes, that's what i have to do.

(I assumed you'd forgotten about the start bit)

The device is listening and waiting for a trama of 101XXXXX in the first byte, so i'm not sure that a start bit is need, but i'm noob on this so..

I still don't see where the 960 comes into this.

I can be wrong, don't take into account, sorry.

Sorry, what is a "trama"?

Can you post any reference material please? What is the device (I'm guessing video equipment)? I can't figure out if each byte has a start, stop and parity, or if they're signalled some other way.

Sorry, what is a "trama"?

Trama is in spanish, i thought in english was the same. I think that in english is plot, but no totally sure. - The first byte that i send will plot 101+5bits. These 5 bits will "say" to the device the variable i want to modify (5 bits = 32 variables possible). - Second and third byte will send the value of the variable selected before (2^16 bits). - Fourth byte value will "say" to the device the next variable i want to modify (like first variable but now bits 000+5 bits of the variable) - Fifth byte will send value (2^8 maximum). - Sixth byte is the sum of the last 5 bytes on complement-2. After each byte plot device has to send a parity bit and stop bit (always 1 and 1).

Can you post any reference material please?

Was made by a spanish company that now is closed and this is why i have to make a new one. I don't know the name, sorry, device is empty of any sticker. I'm working with an arduino one - mega - duemilanove.

I can't figure out if each byte has a start, stop and parity, or if they're signalled some other way.

I have to send 8 bits+1parity bit + 1stop bit ,6 times. Thanks, very appreciated.

I really think it would be easier to use the hardware USART. Serial.begin (15625); should get you close enough to the required bit rate. You'll need to program the USART control registers to accept the parity bit, but that shouldn't be hard (sorry, I'm not near a processor datasheet at the moment). Going with software serial means you'll have to calculate your own delays; not impossible, but if there's another easier way, take it!

Oh thanks,
i will try it.

define F_CPU 16000000UL

define BAUD 15625

//Available modes are asynchronous (00), synchronous (01) and master SPI (11). //UMSEL01 = 0; //UMSEL00 = 0; //USART Parity Mode 1 and 0. UPM01 and UPM00 select the parity. Available modes are none (00), even (10) and odd (11). //UPM01 = 1; //UPM00 = 0; //USART Stop Bit Select. Set to select 1 stop bit. Unset to select 2 stop bits. //USBS0 = 1;

void setup() { //REGISTRE USCR0C //COM ASYNCHRONE bitWrite(UCSR1C,UMSEL00,0); bitWrite(UCSR1C,UMSEL01,0);

//PARITY EVEN bitWrite(UCSR1C,UPM01,1); bitWrite(UCSR1C,UPM00,0);

//8 DATA BIT bitWrite(UCSR1C,UCSZ02,0); bitWrite(UCSR1C,UCSZ01,1); bitWrite(UCSR1C,UCSZ00,1);

//REGISTRE UCSR0B //RECEIVE & TRANSMITT ENABLE bitWrite(UCSR1B,RXEN0,1); bitWrite(UCSR1B,TXEN0,1); delay(100);

Serial1.begin(15625);

Would it be this the way to modify the Serial 1 in the arduino mega 2560? cause i'm not able the get anything...

I'd start with the begin, then mess around with the control registers

I did it with no success =( Code is wrong, should be

//REGISTRE USCR0C //COM ASYNCHRONE bitWrite(UCSR1C,UMSEL10,0); bitWrite(UCSR1C,UMSEL11,0);

//PARITY EVEN bitWrite(UCSR1C,UPM11,1); bitWrite(UCSR1C,UPM10,1);

//8 DATA BIT bitWrite(UCSR1C,UCSZ12,0); bitWrite(UCSR1C,UCSZ11,1); bitWrite(UCSR1C,UCSZ10,1);

//REGISTRE UCSR0B //RECEIVE & TRANSMITT ENABLE bitWrite(UCSR1B,RXEN1,1); bitWrite(UCSR1B,TXEN1,1); delay(100);

//Abrimos puerto a 15625 Serial1.begin(15625);

before i used UMSEL00,UMSEL01,UPM01,... and should be UMSEL10,UMSEL11,UPM11,... for serial 1. Thanks for the help