Usart Command Stops SPI

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francesco.C
Posts: 41
Joined: Thu Feb 26, 2009 6:54 pm
Location: UK

Usart Command Stops SPI

Post by Francesco.C » Sat Jun 13, 2009 4:14 pm

Hi guys,
can you help me to understand this problem?

The code below is under development.
It send a command to serial memory device.
The memory device then replies with its ID code.

The code worked fine until I introduced the 'USART.setbaudrate' command.

Now I cannot get the reply from the memory device!

If I remove the above command the device responds again.

Any idea?

Regards

Francesco C



/////////////////////////////////////
Device = 18F2553
Clock = 24.6
Include "usart.bas"
Include "convert.bas"
Dim n As Integer
USART.setbaudrate(br9600)




//////////////////////// Config SPI registers ////////////

SSPCON1.7=0
SSPCON1.6=0
SSPCON1.5=1 // (SSPEN) Enable serial lines SCK, SDO, SDI For SPI mode
SSPCON1.4=1 // (CKP)Set clock-idle-state as high (polarity)
SSPCON1.3=0 // Set SPI MAster mode = Fosc/64
SSPCON1.2=0 //
SSPCON1.1=1 //
SSPCON1.0=0 //

SSPSTAT.7=0 // (SMP) Data is sampled in midle of data-output-time
SSPSTAT.6=0 // (CKE) Transmition on idle-to-active state. Low->High

////////////////////////////////////////////////////

Output (PORTB.1) // SCK
Input (PORTB.0) // SDI
Output (PORTB.5) // CS
Output (PORTC.7) // Serial Out

///////////////////////////////////////////////////


While true
PORTB.5=0
DelayUS(10)
For n=1 To 5
SSPBUF=$9F // Send data
While SSPSTAT=0

Wend

Next


PORTB.5=1 // Deselect CS
DelayUS(10)
Wend

///////////////////////////////

Post Reply