View previous topic :: View next topic |
Author |
Message |
cassioriguela
Joined: 25 Oct 2011 Posts: 27
|
SPI on dsPIC 33FJ128GP802 doesn't work |
Posted: Tue Nov 22, 2011 10:44 am |
|
|
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 ! |
|
![](templates/subSilver/images/spacer.gif) |
cassioriguela
Joined: 25 Oct 2011 Posts: 27
|
|
Posted: Wed Nov 23, 2011 5:09 am |
|
|
Someone can help, please ? |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Nov 23, 2011 5:32 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
cassioriguela
Joined: 25 Oct 2011 Posts: 27
|
|
Posted: Thu Nov 24, 2011 5:50 am |
|
|
Hello PCM,
Thanks for reply.
I'm using direct register settings because my spi_setup and #use spi doesn't work. Anyway, Thanks. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19386
|
|
Posted: Thu Nov 24, 2011 12:20 pm |
|
|
Check the errata sheets for the chip. I seem to remember there is one to do with this bit....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|