PICmicro & dsPIC >> Source Share for PICmicro & dsPIC

Pages: 1
spikeymikey



Reged: Oct 14 2005
Posts: 3
Loc: UK
J1939 Microchip C Library (modified)
      #20677 - Fri Jan 06 2006 12:54 PM

Hi All,

For anyone who maybe interested i have modified the Microchip J1939 C library (AN930) for use with the PICC-18 compiler.
To request a copy please email me at m_clay@hotmail.com.

Note: This version will only work with PICC18.


Post Extras: Print Post   Remind Me!   Notify Moderator  
luckyAdministrator
Microchip staff
*****

Reged: Oct 06 2003
Posts: 1184
Loc: Brisbane, Australia
Re: J1939 Microchip C Library (modified) [Re: spikeymikey]
      #20687 - Fri Jan 06 2006 07:47 PM

Quote:

To request a copy please email me at [Email]m_clay@hotmail.com.[/Email]




Any chance you could post it here?

--------------------
Matt Luckman
Microchip Technology Inc.


Post Extras: Print Post   Remind Me!   Notify Moderator  
spikeymikey



Reged: Oct 14 2005
Posts: 3
Loc: UK
Re: J1939 Microchip C Library (modified) [Re: lucky]
      #20740 - Sat Jan 14 2006 04:06 AM Attachment (1093 downloads)

Hi,

Attached is a working (PICC18 V8.35PL3) ported version of the Microchip J1939 C library. In order to run this code, the new (WIP) PIC18 CAN Header Files are required.

Mike


Post Extras: Print Post   Remind Me!   Notify Moderator  
Neil_K

***

Reged: Mar 09 2005
Posts: 960
Loc: NY,USA
Re: J1939 Microchip C Library Bugs [Re: spikeymikey]
      #24552 - Thu Oct 12 2006 06:53 PM

First thanks for the Post.
The library does work, pretty good stuff
It saved me some time, so here is what I learned:

Here are some problems I found (with the base code not the translation) Most have to do with arbitray address arbitration.
Bug / Issue
1. in J1939.def
#define J1939_ARBITRARY_ADDRESS 0x80 // 0x80 = Yes, 0 = No

2.in J1939.C
If you chip is not in the defines, the code may not set the CAN port pin direction.

3.in J1939.C
void J1939_Poll( unsigned long ElapsedTime )
The elapsed time says ms (millisec) but it is microsec
the constant should be 2500000L (2.5 seconds)

Note that I got 20uSec @ 8Mhz not the 5mSec in the example

4. in J1939.C
signed char CompareName( unsigned char *OtherName )
the bytes are compared in the wrong order. ( I found this "Common" mistake reported elsewhere).

Try:

Code:

signed char CompareName( unsigned char *OtherName )
{
unsigned char i;

// BUG In Origional Sample Compare is the wrong way
//for (i = 0; (i<J1939_DATA_LENGTH) && (OtherName[i] == CA_Name[i]); i++);

// Byte 0 is LSB
i = J1939_DATA_LENGTH;
do
{
i--;
}
while((i != 0xFF) && (OtherName[i] == CA_Name[i]) );


if (i == 0xFF)
return 0; // Must be equal
else if (CA_Name[i] < OtherName[i] )
return -1;
else
return 1;
}


or code your own.

I did not get the CAN Interupt to work. The code confused the compiler. Some of the code gets call before before the Interupt is enabled. The compiler saw function called from main and the interupt. I stuck with polling for now. Code:






Post Extras: Print Post   Remind Me!   Notify Moderator  
Neil_K

***

Reged: Mar 09 2005
Posts: 960
Loc: NY,USA
Re: J1939 Microchip C Library Bugs [Re: Neil_K]
      #29472 - Wed Aug 29 2007 04:27 PM

Update:
Item #3 of my original post I am wrong it is correct.

There is a Bug in J1939_AddressClaimHandling(). Only if you Have 3 or more fixed addresses. The code as written will only arbitrate 1 one time. Not as many as it needs to to go through the full address list. The other Address Arbitration modes work. Note this affect the original C18 Code too.
here is my fix, but I did not test it with the other modes. So do not add it unless you need it, or test it well
Code:

SendAddressClaim:
// Send Address Claim message for CommandedAddress
CopyName();
OneMessage.Msg.SourceAddress = CommandedAddress;
SET_NETWORK_WINDOW_BITS;

SendOneMessage( (J1939_MESSAGE *) &OneMessage );

if (((CommandedAddress & 0x80) == 0) || // Addresses 0-127
((CommandedAddress & 0xF8) == 0xF8)) // Addresses 248-253 (254,255 illegal)
{
J1939_Flags.Flags.CannotClaimAddress = 0;
J1939_Address = CommandedAddress;

// Set up filter to receive messages sent to this address
SetAddressFilter( J1939_Address );
}
else
{
// We don't have a proprietary address, so we need to wait.
J1939_Address = CommandedAddress; // ADDED NSK, need this here so we know the last failed address
// if we do several address claims to find an address
J1939_Flags.Flags.WaitingForAddressClaimContention = 1;
ContentionWaitTime = 0;
}
}



Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 4 anonymous users are browsing this forum.

Moderator:  jtemples, Dan Henry, Andrew L, mikerj 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is enabled
      UBBCode is enabled

Rating:
Topic views: 13399

Rate this topic

Jump to

Contact Us | Privacy statement HI-TECH Software

Powered by UBB.threads™ 6.5.5