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 configuration on 2nd HW Module (MSSP2), 18F24J11

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



Joined: 26 Aug 2009
Posts: 6

View user's profile Send private message

SPI configuration on 2nd HW Module (MSSP2), 18F24J11
PostPosted: Thu Aug 27, 2009 7:47 pm     Reply with quote

I'm trying to bring up SPI on the 2nd MSSP module of an 18F24J11. It works fine in HW for MSSP1, however, getting things to work on the 2nd module is going no where fast.

I can read out the PPS assignments, I get a 0x09 and 0x0A when reading for SDA2 and SCK2. I've assigned SCK2 and SCK2IN to the same pin as per the datasheet (although this application will be output only since the DOGM162 LCD doesn't have an output of it's own). SDI2 is left unmapped since the datasheet says (a few times) that unused MSSP2/SPI2 function's don't need mapped. I've tried wiring the LCD up to the SPI2 pins and no luck. As far as I can tell I've stopped all other function that preempt PPS on those pins and still I can't get any data out, and PPS appears configured correctly. None the less, the program hangs at the first SPI2 call (spi_write2() in this case).

Any ideas? Anyone had success starting up SPI2?

Code:

#include <18F24J11.h>
#device PASS_STRINGS=IN_RAM
#fuses INTRC_IO, NOWDT, NOPROTECT, NOFCMEN, NOIESO
#use delay(clock=4000000)
#use spi(MASTER, FORCE_HW, BITS=8, SPI1) // Set up SPI1 for a debug LCD
#use spi(MASTER, FORCE_HW, BITS=8, SPI2) // This is the SPI that's not working

// The following EADOGM LCD driver is being used on SPI1 for debug. The
// eventual goal is to move it to SPI2 once there's evidence of SPI2
// working and debug from there.
#define EADOGM162 1 // the model we selected
#define EADOGM_SPI_CS PIN_B3
#define EADOGM_SPI_RS PIN_B2
#define EADOGM_SPI2 1
#include "EA-DOGM_SPI.c"

// PPS overhead, seems to work fine
#define EECON2    0xFA7
#define RPOR3   0xEC9
#define RPOR4   0xECA
#define RPINR22 0xEDC
#define PPSCON   0xEFF
#define IOLOCK   0

#BYTE ADRESL=0xFC3
#BYTE ADRESH=0xFC4

#BYTE RP3=0xEC9
#BYTE RP4=0xECA
#BYTE RI1=0xEFB
#BYTE RTC=0xF3F

void main(void)
{
   int8 a;
   char buff[15];

   delay_ms(100); // power up delay

// Set up remappable pins to have SDO2 and SCK2 and SCK2IN at B0(RP3) and B1(RP4)
#asm
MOVLW 0x55            // 1st unlock code into W
MOVWF EECON2         // 1st unlock code from W to EECON2
MOVLW 0xAA            // 2nd unlock code into W
MOVWF EECON2         // 2nd unlock code from W into EECON2
BCF   PPSCON, IOLOCK   // Clear IOLOCK of PPSCON, unlocking PPS

MOVLW 0x09            // Set value 9 (SDO2) in W
MOVWF RPOR3            // Move W into RPOR3
MOVLW 0x0A            // Set value 10 (SCLK2 Output) in W
MOVWF RPOR4            // Move W into RPOR4
MOVLW 0x04            // Set W to
MOVWF RPINR22         // Moce W into RPINR22 to assign SCL2 Input

MOVLW 0x55            // 1st lock code into W
MOVWF EECON2         // 1st lock code from W to EECON2
MOVLW 0xAA            // 2nd lock code into W
MOVWF EECON2         // 2nd lock code from W into EECON2
BSF   PPSCON, IOLOCK   // Set IOLOCK of PPSCON, locking PPS
#endasm//*/

   ADRESL=0;
   ADRESH=0;
   RTC=0;

   //ADC not needed
   setup_adc(ADC_OFF);
   setup_adc_ports(no_analogs);
 
   //Initialize the debug LCD on SPI1
   eaDogM_Initialize();
   eaDogM_DisplayOn();
   eaDogM_SetPos(0,0);

   a=0;

   while(1)
   {
      a++;
      sprintf(buff,"%04.4i %x %x",a, RP3, RP4);
      eaDogM_SetPos(0,0);
      eaDogM_WriteString(buff); // Works fine.
      spi_write2(buff); // Hangs here, every time. Like it never returns
      delay_ms(100);
   }
}
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