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 support@ccsinfo.com

SPI with 18F8722

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



Joined: 08 Aug 2006
Posts: 49

View user's profile Send private message

SPI with 18F8722
PostPosted: Thu Aug 10, 2006 1:26 pm     Reply with quote

Hello All :)
I am going through a very hard time to setup MAX3110 with 18F8722 in SPI mode. I am using the second spi D4,D5,D6 pins.

I am not able to write and read the configuration data from max3110. When I write 0xc40a I should read back 0x4000.
When I read 0x4000 I should read back the current setting in the SSP2BUF. I am not able to. My f8722 is in master mode

Here are my init setup of ssp2.

[list=]
//These for a 18F chip
#define CS_LOW output_low(PIN_J1)
#define CS_HIGH output_high(PIN_J1)

#byte SSP2CON = 0xF63
#byte SSP2STAT = 0xF64
#byte I2C2BUF = 0xF65
#byte SSP2BUF = 0xF66
#define SSP2C_INIT 0x00
#bit SSP2EN = 0xF63.5
#define SSP2S_INIT 0x40
#bit BF = SSP2STAT.0
#bit SMP = SSP2STAT.7
#bit CKE = SSP2STAT.6
#bit CKP = SSP2CON.4
#bit SSPM3 = SSP2CON.3
#bit SSPM2 = SSP2CON.2
#bit SSPM1 = SSP2CON.1
#bit SSPM0 = SSP2CON.0

#define READ_SSP() (SSP2BUF)
#define WAIT_FOR_SSP() while(!BF)
#define WRITE_SSP(x) SSP2BUF = (x)
#define CLEAR_WCOL() SSP2CON = SSP2CON & 0x3F

void max3110_init(void){

SSP2BUF = 0x0000;
SSP2EN = 1;
SMP = 1;
CKE = 0;
CKP = 0;
SSPM3 = 0;
SSPM2 = 0;
SSPM1 = 0;
SSPM0 = 1;

}

// this is where i read and write operation to max3110

void max3110(void){

// Mconfig = 0xC40a;

CS_LOW;
WRITE_SSP(0xc4); // send msb
WAIT_FOR_SSP();
msb=READ_SSP();

WRITE_SSP(0x0a); // send lsb
WAIT_FOR_SSP();
lsb=READ_SSP();
CS_HIGH;

readconfig = ((unsigned short)msb << 8 | lsb);

delay_us(10);

CS_LOW;
WRITE_SSP(0x40); // send msb
WAIT_FOR_SSP();
msb=READ_SSP();

WRITE_SSP(0x00); // send lsb
WAIT_FOR_SSP();
lsb=READ_SSP();
CS_HIGH;

}

Is there any thing I am missing.

PLease help me
_________________
Thanks

mkr
Ttelmah
Guest







PostPosted: Thu Aug 10, 2006 2:54 pm     Reply with quote

One obvious thought. How have you got TRIS configured?. Remember if you are taking control of the SPI yourself, _you_ need to set the TRIS register toput the bits into the right mode. Check the chip data sheet for the required direction setting for the bits.

Best Wishes
mkr



Joined: 08 Aug 2006
Posts: 49

View user's profile Send private message

1 thing i noticed
PostPosted: Thu Aug 10, 2006 3:08 pm     Reply with quote

the tris_d is set accordingly. D4 is SDO, D5 is SDI, D6 is SCK so thats works out to be 0x20 for port D so that is set_tris_d(0x20)
The other thing i noticed is that the clock is not coming out of D6 pin. wondering why. any thoughts
_________________
Thanks

mkr
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Aug 10, 2006 5:53 pm     Reply with quote

You shouldn't poll the BF flag:
Quote:
29. Module: MSSP (SPI Mode)
In SPI mode, the Buffer Full Status bit, BF
(SSPxSTAT<0>), should not be polled in software
to determine when the transfer is complete.

Read more about this in the new revision C of the PIC18F8722 errata document and two possilble work arounds.

Code:
 SSP2BUF = 0x0000;
This is tricky: writing a 16 bit value to an 8 bit register. It is also possible the chip select line and SSP2 module are active at this point which causes you to wite data to the MAX3110.

I didn't have much time to study the MAX3110 datasheet but I think you have to change the SPI mode to CKP = 0, CKE = 1, SMP = 0,
mkr



Joined: 08 Aug 2006
Posts: 49

View user's profile Send private message

Thanks for the thought, queries about CKP and CKE
PostPosted: Thu Aug 10, 2006 7:40 pm     Reply with quote

Thanks for your resource full reply. I looked at the f8722 errata. Your right. I should not poll for BF to change state.

Another thing about CKP and CKE. Based on MAX3110E data sheet, legal value for CKP =0 and CKE = 0. Is CPOL and CPHA same as CKP and CKE. I am getting confused. In the data sheet of MAX3110, CPOL =0 and CPHA=0 has to be set.

Your suggestion greatly appreciated
_________________
Thanks

mkr
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 3:02 am     Reply with quote

I can recommend you to read http://www.ucpros.com/work%20samples/Microcontroller%20Communication%20Interfaces%202.htm. This is a short article on several microcontroller Interfaces including SPI.

CPOL = Clock Polarity, it defines the clock's logic level in idle state. Working is identical to the Microchip CKP bit.

CPHA = Clock Phase, it defines on which clock edge the data is shifted out for sending and shifted in for reading. The Microchip CKE bit has the same functionality but... it is defined inverted, so CKE = ! CPHA.
See also http://www.ccsinfo.com/forum/viewtopic.php?t=8747

CPOL =0, CPHA = 0 translates to --> CKP = 0, CKE =1
SMP is always set to 0, only for some very rare non-standard communications it has to be set to 1.
mkr



Joined: 08 Aug 2006
Posts: 49

View user's profile Send private message

perfect its working
PostPosted: Fri Aug 11, 2006 8:41 am     Reply with quote

Thanks a lot. I changed the CKE =1 and CKP =0 and also followed the errata for F8722 for BF on SSP2STAT.0. I am not polling this bit.[/quote]
_________________
Thanks

mkr
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