Pages: [1]   Go Down
Author Topic: Library for Modelltrains  (Read 1852 times)
0 Members and 1 Guest are viewing this topic.
Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Netherlands
Offline Offline
Sr. Member
****
Karma: 1
Posts: 290
(:-)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12736
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
« Last Edit: November 03, 2010, 01:17:24 pm by bcook » Logged

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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
Logged

Rob Tillaart

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

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5551
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Sweden
Offline Offline
Full Member
***
Karma: 11
Posts: 237
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Do you mean this to Transmitt?:

Code:
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:
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
Logged

Pages: [1]   Go Up
Jump to: