CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ENC28J60 and PIC24 compatibility
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Sep 26, 2009 1:45 pm     Reply with quote

FvM wrote:
Did you try to use the address error trap to locate resets caused by data alignment errors?
http://www.ccsinfo.com/forum/viewtopic.php?t=36479

The other "popular" reason for PIC24 resets is PCD's too small default stack assignment. http://www.ccsinfo.com/forum/viewtopic.php?t=40083


Haven't got that far yet.

Still cleaning up stuff I know exists... and NOW -- NOW I can't believe that I'm seeing hardware SPI on the Explorer16 doesn't work (more precisely, a PIC24FJ128GA010).

The SCK pin does nothing (in hardware mode) and the SDO pin only shows about 3-4 pulses (depending on how one views them)


Will someone out there with the same CPU crack out their scope and verify this for me?

I have some sample code that puts out data to both SPI1 and SPI2 one in Hardware mode and the other in Software.

Actually, PCD complains about SPI1's pin definitions being bad even though I'm looking at the datasheet and seeing (maybe erroneously) that they are correct. So SPI is the one in software mode. (removing the PIN assignments makes the error go away and then the unit generates the same signals at SPI2 in hardware mode.)

Both SPI "ports" work fine with FORCE_SW (slowly) showing the pins are capable of drive. Debug Watch shows the open-drain config as should be (push-pull, NOT OD)


EDIT:

Code removed: Found problem. CCS Sets the speed of the SPI too high (looking into who's the guilty party)...

Have my test code sending now. Just have to figure out why.

EDIT @ 4:56pm:

It's a CCS Problem.

The .H file has defines for a normal SPI unit and this isn't that kind of SPI.
So if I try to set the SPI prescalers manually (bit manipulation) THAT doesn't even work. So this is a bug for CCS.

EDIT @ 20090927 1:06pm:
See code below. For whatever reason with this PIC, the SPI module must be disabled before changing the prescalers. (and it's not in the errata for the chip or mentioned in the datasheet - MCHP BUG!)

So CCS sets the speed to high by default. The CCS .H file doesn't have parms or a compiler command to actually reset the SPI properly for this device at the moment.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D


Last edited by bkamen on Sun Sep 27, 2009 12:25 pm; edited 1 time in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Sep 27, 2009 4:55 am     Reply with quote

Quote:
So if I try to set the SPI prescalers manually (bit manipulation) THAT doesn't even work. So this is a bug for CCS.

I can hardly imagine, how you managed it. I never experienced any problems in PIC24 SPI speed setup yet. You should post the respective code for clarity.

The previous reported problems may be related to the #use spi statement. I never had a reason to use it with hardware SPI.
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Sep 27, 2009 12:13 pm     Reply with quote

I can do that.

I think I might ask Darren to add a PCD forum.

Sometimes this "all eggs in 2 baskets" just doesn't segregate the traffic enough to be useful.

Anyway -- I did this...

Code:
struct _SPI_STAT {
   unsigned int1   SPIRBF;      // RCV BUF FULL
   unsigned int1   SPITBF;      // TX BUF FULL
   unsigned int8   SISEL:3;   // Interrupt operation selection
   unsigned int1   SRXMPT;      // RCV FIFO Empty
   unsigned int1   SPIROV;      // RCV BUFF OVERFLOW
   unsigned int1   SRMPT;      // Shift Register Empty 1=ok to send

   unsigned int8   SPIBEC:3;   // FIFO Buffer Element Count Bits
   unsigned int1   bit11;      // Unused
   unsigned int1   bit12;      // Unused
   unsigned int1   SPISIDL;   // Stop module when Idle.
   unsigned int1   bit14;      // Unused
   unsigned int1   SPIEN;      // Enable Module
};

struct _SPI_CON1 {
   unsigned int8   PPRE:2;   // Primary Prescale    11  = 1:1
   unsigned int8   SPRE:3;   // Secondary Prescale  111 = 1:1
   unsigned int1   MSTEN;   // Master Mode Enable
   unsigned int1   CKP;   // Clock Polarity Select
   unsigned int1   SSEN;   // SlaveSelect Enable

   unsigned int1   CKE;   // Clock Edge Select
   unsigned int1   SMP;   // Sample Phase
   unsigned int1   MODE16;   // 16Bit mode when == 1
   unsigned int1   DISSDO;   // Disable SDO
   unsigned int1   DISSCK;   // Disable SCK
   unsigned int1   bit13;   // Unused
   unsigned int1   bit14;   // Unused
   unsigned int1   bit15;   // Unused
};


struct _SPI_STAT SPI1STAT;
struct _SPI_STAT SPI2STAT;
#word SPI1STAT = getenv("sfr:SPI1STAT")
#word SPI2STAT = getenv("sfr:SPI2STAT")


struct _SPI_CON1 SPI1CON1;
struct _SPI_CON1 SPI2CON1;
#word SPI1CON1 = getenv("sfr:SPI1CON1")
#word SPI2CON1 = getenv("sfr:SPI2CON1")

   spi1stat.spien = 0;
   spi2stat.spien = 0;
   spi1con1.spre = 0x6;
   spi2con1.spre = 0x6;

   spi1stat.spien = 1;
   spi2stat.spien = 1;


Now I just need to resolve the bit-twiddling problem I described in another post as the nCS lines for the SPI devices are suffering because of this.. and it doesn't feel like a PCD problem so much maybe as me doing something wrong... but then again, maybe not.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Sep 27, 2009 3:58 pm     Reply with quote

So you say, it's working now - when disabling the SPI interface during changing the clock divider?

Quote:
The CCS .H file doesn't have parms or a compiler command to actually reset the SPI properly
setup_spi(0) does in my opinion.
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Sep 27, 2009 4:05 pm     Reply with quote

SPI transmission is occuring at 8Mb/s -- yes.

I write to SPI1BUF (or SPI2BUF) and the bytes go out as expected.

PCD by default sets the PPRE and SPRE to scale by 1:1 which is invalid for a part with a Tcy of 16MHz.

There's nothing in the header file for this PIC that allows me to set the SPRE to 1:2.. so I have to do it by hand. (shown above)

Now I just have to figure out the problem with the chip selects in my other post.

:D
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 12:34 am     Reply with quote

Ok, this is on hold until I get a new PIM from MCHP to replace what appears to be a bad 24FJ128GA010.

I have a trouble ticket in with MCHP. My PIM is wonky.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 2:33 am     Reply with quote

Quote:
There's nothing in the header file for this PIC that allows me to set the SPRE to 1:2
Yes, that's right. It's pretty easy however, because setup_spi() is writing the configuration mask directly to the SPICON1 register. So you can supplement it as required. I have my private definitions for this purpose.
Code:
#define SPI_CLK_DIV_2    0x001B
#define SPI_CKE          0x0100
#define SPI_CKP          0x0040
#define SPI_SMP          0x0200

#define SPI_MODE_0 (SPI_CKE)
#define SPI_MODE_1 (0)
#define SPI_MODE_2 (SPI_CKP | SPI_CKE)
#define SPI_MODE_3 (SPI_CKP)
// as an example
setup_spi(SPI_MASTER | SPI_MODE_0 |SPI_CLK_DIV_2);
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 11:27 am     Reply with quote

I've thought about doing that, but I'm never 100% sure what some of the predefined functions are doing. So I just do them myself. -- Remove all doubt -- especially when debugging!!

:D

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 28, 2009 11:35 am     Reply with quote

FvM wrote:
So you say, it's working now - when disabling the SPI interface during changing the clock divider?

Quote:
The CCS .H file doesn't have parms or a compiler command to actually reset the SPI properly
setup_spi(0) does in my opinion.


Sorry, I meant to say "setup" not reset... in the grand sense of "past spi_setup, other than making my own #defines or direct twiddling".

I hear ya on SPI_SETUP().. Hehe...

:D
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Oct 11, 2009 7:10 pm     Reply with quote

Bump!

Ok, I have my new PIC24 (as mentioned in the other thread) and I've got stuff communicating to devices (that I can tell) on this Explorer16 board.

Now the Display says no DHCP address being assigned.

So now I have to go dig in the stack. Might find what it is tonight..

I'm struggling on the value of getting such an old stack running.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1619
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Oct 12, 2009 1:53 am     Reply with quote

As a side note: the pre-compiled .HEX file that comes with the new TCP/IP Stack (v5.10) when programmed onto the Explorer16 and the ENC28J60 fire right up and work fine.

(groan)

With the CCS version'd TCP/IP 3.75, it works under PCH, but now I'm stuck trying to figure out why the UDP checksums are failing now that the project compiles for the PIC24/Explorer16.

----------------------------

I'm stuck between trying to get the known older stack that compiles and runs with CCS working on the 24H with the needed mods...

Or jumping right to the 5.1stack which now needs 2 passes.. one to make it CCS happy and then the next to make it PIC24H happy.

Ugh.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group