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

SPI on dsPIC 33FJ128GP802 doesn't work

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cassioriguela



Joined: 25 Oct 2011
Posts: 27

View user's profile Send private message

SPI on dsPIC 33FJ128GP802 doesn't work
PostPosted: Tue Nov 22, 2011 10:44 am     Reply with quote

Hello my friends,

I have a problem with SPI. I did a test code so i'm writing a byte on SPI and getting nothing on scope. In addition, my writedata function get hangs on SPI1TBF bit.



My code:


Code:

#include "main.h"

#BYTE SPI1CON = 0x242
#BYTE SPI1BUF = 0x248
#BYTE SPI1STAT = 0x240
#BYTE SPI1CON2 = 0x244

#BIT DISSCK = SPI1CON.12
#BIT DISSDO = SPI1CON.11
#BIT MODE16 = SPI1CON.10
#BIT SMP    = SPI1CON.9
#BIT CKE    = SPI1CON.8
#BIT SSEN   = SPI1CON.7
#BIT CKP    = SPI1CON.6   
#BIT MSTEN  = SPI1CON.5
#BIT SPRE4  = SPI1CON.4
#BIT SPRE3  = SPI1CON.3
#BIT SPRE2  = SPI1CON.2
#BIT PPRE1  = SPI1CON.1
#BIT PPRE0  = SPI1CON.0

#BIT SPI1EN  = SPI1STAT.15
#BIT SPI1RBF = SPI1STAT.0
#BIT SPI1TBF = SPI1STAT.1
#BIT SPISIDL = SPI1STAT.13
#BIT SPIROV = SPI1STAT.6

void writeData(unsigned char data)
{
   SPI1BUF = data;
   while(SPI1TBF)
   {
      fprintf(COM,"DEBUG...\r\n");
   }
}

void main()
{   
   int a = 0;
   int b;

   char d = 0x50;

   SPI1EN = 0;
   DISSCK = 0;
   DISSDO = 0;
   MODE16 = 0;
   SMP = 1;
   CKE = 0;
   CKP = 1;
   
   SPRE4 = 1;
   SPRE3 = 1;
   SPRE2 = 0 ;
   PPRE1 = 1;
   PPRE0 = 0;

   SPI1EN = 1;
   MSTEN = 1;

   SPI1CON2 = 0;
   SPISIDL = 0;
   SPIROV = 0;

        setup_wdt(WDT_OFF);
        setup_timer1(TMR_DISABLED);
   set_tris_b(0b1111001011111111);

   


   while(TRUE)
   {
      fprintf(COM,"Main...\r\n");
   
      writeData(d);

       delay_ms(500);
      
   }

}


Can someone help me ? .Thanks guys !
cassioriguela



Joined: 25 Oct 2011
Posts: 27

View user's profile Send private message

PostPosted: Wed Nov 23, 2011 5:09 am     Reply with quote

Someone can help, please ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 23, 2011 5:32 pm     Reply with quote

The reason you got no replies is, most of us don't have the PCD compiler.
The few people that do have it, don't want to use direct register settings.
I am just trying to explain why you don't get any replies.
cassioriguela



Joined: 25 Oct 2011
Posts: 27

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 5:50 am     Reply with quote

Hello PCM,

Thanks for reply.

I'm using direct register settings because my spi_setup and #use spi doesn't work. Anyway, Thanks.
Ttelmah



Joined: 11 Mar 2010
Posts: 19539

View user's profile Send private message

PostPosted: Thu Nov 24, 2011 12:20 pm     Reply with quote

Check the errata sheets for the chip. I seem to remember there is one to do with this bit....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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