ragi
Junior Member level 3
Hi all ,
I have written code for PIC18LF24K22 to work as slave. When I sent data from SPI master(CHEETAH Adaptor) it is not able to receive the data. So I checked input functionality of receiving pin by just forcing vdd to that pin and checked the port value in register , it was showing 0.
So same thing i tried on my pic18f45k20 evm board. I checked PORT A ,PORTB . PORTC. For PORTC i am able to check input in register , but not for PORTA and PORTB. Have attached the code below which i used for this.
Please Suggest if I need to do more on Coding/Hardware. Thanks in Advance
program for spi as slave :
I have written code for PIC18LF24K22 to work as slave. When I sent data from SPI master(CHEETAH Adaptor) it is not able to receive the data. So I checked input functionality of receiving pin by just forcing vdd to that pin and checked the port value in register , it was showing 0.
So same thing i tried on my pic18f45k20 evm board. I checked PORT A ,PORTB . PORTC. For PORTC i am able to check input in register , but not for PORTA and PORTB. Have attached the code below which i used for this.
Please Suggest if I need to do more on Coding/Hardware. Thanks in Advance
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include "p18f45k20.h" #pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 30 // CONFIG2L void main (void) { unsigned char data ; TRISC = 0b11111111; TRISD = 0b00000000; TRISA = 0b11111111; LATDbits.LATD0 = 0; // for led bit data = PORTAbits.RA5 ; if ( PORTAbits.RA5 == 1 ) LATDbits.LATD0 = 1; /* Light the LEDs */ while (1) ; }
program for spi as slave :
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 #pragma config WDTEN = OFF, WDTPS = 32768 // CONFIG2H #include <p18lf24k22.h> #include "clock.h" #include "Uart_1.h" #include <spi.h> #define DEBUG 1 #define HIGH 1 #define LOW 0 #define LED LATAbits.LATA1 #define TUNE_READY LATAbits.LATA0 #define D_POT_1 LATCbits.LATC2 #define D_POT_2 LATCbits.LATC1 #define D_POT_3 LATCbits.LATC0 #define RF_Sw_A1 LATAbits.LATA4 #define RF_Sw_A2 LATAbits.LATA5 #define RF_Sw_B1 LATAbits.LATA6 #define RF_Sw_B2 LATAbits.LATA7 unsigned char SPI_Recv[10]; void main(void) { unsigned char i,channel = 0, data = 0 ,w , temp; CloseSPI2(); for(w=0;w<25;w++) SPI_Recv[w]=0; TRISAbits.TRISA1 = 0; //Makes 1st bit of PORTA Output for LED TRISBbits.TRISB0 = 1; TRISBbits.TRISB1 = 1; TRISBbits.TRISB2 = 1; LED = HIGH ; while(1) { temp = PORTBbits.RB0 ; channel = PORTAbits.RA1 ; data = PORTBbits.RB2 ; } if(clock_configure(16)) //set the CPU CLOCK to 16Mhz { for(i=3; i>1; i--) { //Blinking Led twice to indicate clock config Done/ LED = LOW; //Makes 1st bit of PORTA at Logic Low //RED_LED off delay(); LED = HIGH; //Makes 1st bit of PORTA at Logic High //RED_LED on delay(); } } OpenSPI2(SLV_SSON,MODE_00,SMPEND); for(i=0;i<100;i++); temp = ReadSPI2(); while(1) { /* while (!DataRdySPI2()); LED = LOW; getsSPI2(SPI_Recv,10); while (!DataRdySPI()); LATDbits.LATD1 = ~LATDbits.LATD1 ; temp = ReadSPI(); //End of program */ } CloseSPI2(); }//MAIN