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

Cannot write SPI2CON1 Register...

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



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

Cannot write SPI2CON1 Register...
PostPosted: Mon Feb 08, 2010 11:03 pm     Reply with quote

I am trying to write the SPI2CON1 register, and it is not accepting the value written to it:

Code:

#fuses XT, PR_PLL, NOCOE, NOWRTB, NOPUT, NOWRTSS, NOPROTECT, NORSS, NOWDT, NOWINDIS

 #FUSES NOWRT                 //Program memory not write protected
 #FUSES DEBUG         //Debug mode for ICD
 #FUSES NOWRTB      //Boot block not write protected
 #FUSES NOSSS         //No secure segment
 #FUSES NORSS         //No secure segment RAM


 ...

 i16_previous = SPI2CON1;// Get previous state.i16_new = 0x0020;      // Data we are sending...
 SPI2CON1 = i16_new;      // Write data to the register
 i16_result = SPI2CON1;   // Read data from the register

 SPI2STAT = 0b1000000000000000; // Enable SPI

 // Print out the written and read data.
 fprintf( SERIAL2, "\n\r -Previous: %LX, New: %LX, Result: %LX", i16_previous, i16_new, i16_result);


Program Output: -Previous: 0061, New: 0020, Result: 0061

List File:
Code:

....................          i16_previous = SPI2CON1;// Get previous state. 
 11C2:  PUSH    262
 11C4:  POP     131A
 ....................          i16_new = 0x0020;      // Data we are sending... 
 11C6:  MOV     #20,W4
 11C8:  MOV     W4,131C
 ....................          SPI2CON1 = i16_new;      // Write data to the register 
 11CA:  PUSH    131C
 11CC:  POP     262
 ....................          i16_result = SPI2CON1;   // Read data from the register 
 11CE:  PUSH    262
 11D0:  POP     131E
 ....................   
 ....................          SPI2STAT = 0b1000000000000000; // Enable SPI 
 11D2:  MOV     #8000,W4
 11D4:  MOV     W4,260


Does anyone know if there a "write protect" mode for the SPI register that I need to disable to accomplish this?


Compiler: 4.104
Device: DSPIC33FJ64GP310-I/PT
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.


Last edited by icesynth on Tue Feb 09, 2010 12:15 am; edited 6 times in total
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Feb 08, 2010 11:33 pm     Reply with quote

From your code snippet, I can't see what you are actually doing, particularly if SPI2CON1 is defined correctly.

There is surely no write protect for SPI registers. SPIxCON should be configured, before setting SPIEN.
From your code, the previous state of SPIEN can't be seen.
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

PostPosted: Tue Feb 09, 2010 12:05 am     Reply with quote

Updated the code and the result to show the value before writing....
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
icesynth



Joined: 03 Sep 2007
Posts: 32
Location: Edmonton, Alberta

View user's profile Send private message Visit poster's website

Solved
PostPosted: Tue Feb 09, 2010 12:18 am     Reply with quote

Thanks for the tip, it turns out that the SPI module must be disabled before the mode is changed.
_________________
Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc.
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