Go Down

Topic: Library for Modelltrains (Read 2144 times) previous topic - next topic

JanD

Hello,

could some one please give me a link to a LocoNet or XpressNet library for arduino? Or make one?

If you can make me one, here are the documentations:

XpressNet:
http://www.opendcc.de/info/xpressnet/xpressnet.html
http://www.lenz.com/manuals/xpressnet/xpressnet.pdf

LocoNet:
http://www.digitrax.com/ftp/loconetpersonaledition.pdf

XpressNet is a RS458 protocol so it shouldn't be so hard to write a library.

Please help me!!!

Jan

wortelsoft

If it isn't so hard why don't you start writing it yourself?

JanD

I started on a library for XpressNet but gave up as I came to the priority, call etc bits. I have programmed a lot in my live and I am on the Qt Dev Days in SFO right now but I have never worked with serial or writing any library.

So don't assume I haven't even looked at it, because I have.


I don't mind if it needs a different ATmega to convert from XpressNet to USART to get better timing, if it needs to.

Jan

Coding Badly

#3
Nov 03, 2010, 07:14 pm Last Edit: Nov 03, 2010, 07:17 pm by bcook Reason: 1

In which case, you need to make your questions more specific.  As you've found, asking "will you folks do this for me" isn't going to get much traction.  But asking, "Is it possible to do 9 bit serial?", is much more likely to move the project along.

So, does anyone know if it is possible to do 9 bit serial with an Arduino?  Has anyone done this?  Is anyone willing to share a bit of code?

From what I can tell, the first byte of a message has the "ninth bit" set high and the remaining bytes have the "ninth bit" set low.  This appears to be a way to wake / attention a slave by causing a "parity high" interrupt.

JanD

Ok, thanks Coding Badly.

So:

Has anyone any clue about if it's possible to do this 9-bit serial with arduino? Does anyone perhaps have some code?

Jan

robtillaart

Hi Jan,

Have a look at the NewSoftSerial library, latest version @ http://arduiniana.org/. There is a function called - void NewSoftSerial::write(uint8_t b) - in the cpp file that clocks out 8 bits using the mask to count. This could be the basis for clocking out your 9 bits. As 9 bits does not fit in a byte, you will have to use an int for the mask and for the value being sent, and a loop that goes from 1..9 of course.
Code: [Select]
for (byte mask = 0x01; mask; mask <<= 1)
   {
     if (b & mask) // choose bit
       tx_pin_write(HIGH); // send 1
     else
       tx_pin_write(LOW); // send 0
     tunedDelay(_tx_delay);
   }

Hopes this get you started.
Rob
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

cr0sh

I was just looking at the ATMega328 datasheet, and there was some C code in there for doing 9-bit data transmission with the hardware UART...
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

JanD

Do you mean this to Transmitt?:

Code: [Select]
void USART_Transmit( unsigned int data )
{
/* Wait for empty transmit buffer */
while ( !( UCSRnA & (1<<UDREn))) )
;
/* Copy 9th bit to TXB8 */
UCSRnB &= ~(1<<TXB8);
if ( data & 0x0100 )
UCSRnB |= (1<<TXB8);
/* Put data into buffer, sends the data */
UDRn = data;
}


And this to Recieve?:

Code: [Select]
unsigned int USART_Receive( void )
{
unsigned char status, resh, resl;
/* Wait for data to be received */
while ( !(UCSRnA & (1<<RXCn)) )
;
/* Get status and 9th bit, then data */
/* from buffer */
status = UCSRnA;
resh = UCSRnB;
resl = UDRn;
/* If error, return -1 */
if ( status & (1<<FEn)|(1<<DORn)|(1<<UPEn) )
return -1;
/* Filter the 9th bit, then return */
resh = (resh >> 1) & 0x01;
return ((resh << 8) | resl);
}



If yes, should I put the two functions into the end of the code for the XpressNet transmitter/reciever and when use the two functions like Serial.print(); and Serial.read(); ? Or is there any difference between how they work?

Jan

Go Up