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 problem

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



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

SPI problem
PostPosted: Mon Feb 04, 2008 2:27 pm     Reply with quote

Good day.

I have a problem using hardware SPI. Seems that cpu goes into deadlock in the initialization part. Here is a sample code:
Code:
CCS PCH C Compiler, Version 4.057, 33367               04-Feb-08 22:01

               Filename: D:\Programe\Pic\Exp\Exp.lst

               ROM used: 150 bytes (0%)
                         Largest free fragment is 65386
               RAM used: 7 (0%) at main() level
                         8 (0%) worst case
               Stack:    1 locations

*
00000:  GOTO   0038
.................... #define CPU_CLOCK  20000000
.................... #include <18F8722.h>
.................... //////// Standard Header file for the PIC18F8722 device ////////////////
.................... #device PIC18F8722
.................... #list
.................... 
.................... #fuses HS,NOWDT,NOPROTECT,NOLVP
.................... #use delay(clock = CPU_CLOCK)
.................... #use rs232(baud=115000, parity=N, xmit=PIN_G1, rcv=PIN_G2, bits = 8, ERRORS, STREAM = Hard)
.................... #use spi(FORCE_HW, SPI1, MASTER, BITS=8, MODE=3, STREAM=MmcSd)
00026:  MOVF   FC9,W
00028:  MOVFF  06,FC9
0002C:  BTFSS  FC5.0
0002E:  BRA    002C
00030:  MOVFF  FC9,01
00034:  GOTO   007A (RETURN)
.................... 
.................... void main()
.................... {
00038:  CLRF   FF8
0003A:  BCF    FD0.7
0003C:  CLRF   FEA
0003E:  CLRF   FE9
00040:  BSF    F7C.3
00042:  MOVLW  2A
00044:  MOVWF  F6F
00046:  MOVLW  00
00048:  MOVWF  F7D
0004A:  MOVLW  A6
0004C:  MOVWF  F6C
0004E:  MOVLW  90
00050:  MOVWF  F6B
00052:  BCF    FC6.5
00054:  BCF    F94.5
00056:  BSF    F94.4
00058:  BCF    F94.3
0005A:  MOVLW  30
0005C:  MOVWF  FC6
0005E:  MOVLW  00
00060:  MOVWF  FC5
00062:  MOVF   FC1,W
00064:  ANDLW  C0
00066:  IORLW  0F
00068:  MOVWF  FC1
0006A:  MOVLW  07
0006C:  MOVWF  FB4
0006E:  CLRF   05
....................     spi_xfer(0xFF);
00070:  MOVLW  FF
00072:  MOVWF  06
00074:  MOVLW  08
00076:  MOVWF  07
00078:  BRA    0026
....................     printf("Hello World!\n");
0007A:  CLRF   06
0007C:  MOVF   06,W
0007E:  RCALL  0004
00080:  INCF   06,F
00082:  MOVWF  00
00084:  MOVF   00,W
00086:  BTFSS  FA4.4
00088:  BRA    0086
0008A:  MOVWF  F6D
0008C:  MOVLW  0D
0008E:  SUBWF  06,W
00090:  BNZ   007C
....................     for(;;);
00092:  BRA    0092
.................... }
00094:  BRA    0094

Configuration Fuses:
   Word  1: 0200   HS NOIESO NOFCMEN RESERVED
   Word  2: 1E19   NOBROWNOUT NOWDT BORV25 NOPUT WDT32768
   Word  3: 83F3   CCP2C1 NOLPT1OSC MCLR MCU RESERVED WAIT BW16 ABW20 ECCPE
   Word  4: 0000   NOSTVREN DEBUG NOLVP NOXINST RESERVED
   Word  5: C0FF   NOPROTECT NOCPD NOCPB
   Word  6: E0FF   NOWRT NOWRTD NOWRTC NOWRTB
   Word  7: 40FF   NOEBTRB NOEBTR
In debug mode, i can see that PC executes the BTFSS FC5.0 and BRA 002C (@0002C) infinitely. I guess that he's expecting that SEN flag from SS1CON2 to be cleared by HW. Somehow this is not happening. If i use spi_read instead spi_xmit, seems to be working... but why?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 04, 2008 6:27 pm     Reply with quote

I think it's a bug. Here are the results with vs. 4.066. Note that it's
now checking the BF flag.
Code:

... #use spi(FORCE_HW, SPI1, MASTER, BITS=8, MODE=3, STREAM=MmcSd) 
00026:  MOVF   FC9,W
00028:  MOVFF  06,FC9
0002C:  BTFSS  FC7.0   // SSP1STAT.BF
0002E:  BRA    002C
00030:  MOVFF  FC9,01
00034:  GOTO   007A (RETURN)
.................... 
.................... void main() 
.................... { 
00038:  CLRF   FF8
0003A:  BCF    FD0.7
0003C:  CLRF   FEA
0003E:  CLRF   FE9
00040:  BSF    F7C.3
00042:  MOVLW  2A
00044:  MOVWF  F6F
00046:  MOVLW  00
00048:  MOVWF  F7D
0004A:  MOVLW  A6
0004C:  MOVWF  F6C
0004E:  MOVLW  90
00050:  MOVWF  F6B
00052:  BCF    FC6.5
00054:  BCF    F94.5
00056:  BSF    F94.4
00058:  BCF    F94.3
0005A:  MOVLW  30
0005C:  MOVWF  FC6
0005E:  MOVLW  00
00060:  MOVWF  FC7
00062:  MOVF   FC1,W
00064:  ANDLW  C0
00066:  IORLW  0F
00068:  MOVWF  FC1
0006A:  MOVLW  07
0006C:  MOVWF  FB4
0006E:  CLRF   05
.................... spi_xfer(0xFF); 
00070:  MOVLW  FF
00072:  MOVWF  06
00074:  MOVLW  08
00076:  MOVWF  07
00078:  BRA    0026
.................... printf("Hello World!\n"); 
0007A:  CLRF   06
0007C:  MOVF   06,W
0007E:  RCALL  0004
00080:  INCF   06,F
00082:  MOVWF  00
00084:  MOVF   00,W
00086:  BTFSS  FA4.4
00088:  BRA    0086
0008A:  MOVWF  F6D
0008C:  MOVLW  0D
0008E:  SUBWF  06,W
00090:  BNZ   007C
.................... 
.................... for(;;); 
00092:  BRA    0092
.................... } 
.................... 
Pret



Joined: 18 Jul 2006
Posts: 92
Location: Iasi, Romania

View user's profile Send private message

PostPosted: Tue Feb 05, 2008 4:48 pm     Reply with quote

Yes... i think so. Guess that i should update my compiler. Lately... i got more and more sceptic on CCS's reliability...

Thanks for support.
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