Microcontroller › PIC › Unable to implement SPI communication using mikroc library
- This topic has 0 replies, 1 voice, and was last updated 8 years, 1 month ago by umair.
Viewing 1 post (of 1 total)
-
AuthorPosts
-
September 8, 2016 at 1:11 pm #4553umairParticipant
I want to implement spi protocol between two pic18f4550 using mikroc library but cant? I am sending data from master to slave and displaying both controller output on uart. Please help me in removing error in my code…
Here is my code
MASTER CODE:
/*MASTER CODE*/sbit chipselect at RD0_bit;sbit chipselect_Direction at TRISD0_bit;sbit SDO at RC7_bit;sbit SDO_Direction at TRISC7_bit;sbit SDI at RB0_bit;sbit SDI_Direction at TRISB0_bit;sbit SCK at RB1_bit;sbit SCK_Direction at TRISB1_bit;char senddata1='1';char senddata2='2';char senddata3='3';char senddata4='4';char senddata5='5';void main() {ADCON0 = 0x3C; // Disabling the ADC module which is multiplexed with SPI pinsADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pinsCMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pinsSPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexed with SPI pinschipselect_Direction=0;SDI_Direction=1;SDO_Direction=0;SCK_Direction=0;chipselect=0;UART1_Init(9600);delay_ms(100);SPI1_Init();delay_ms(100);do{SPI1_Write(senddata1);UART1_Write(senddata1);delay_ms(1000);SPI1_Write(senddata2);UART1_Write(senddata2);delay_ms(1000);SPI1_Write(senddata3);UART1_Write(senddata3);delay_ms(1000);SPI1_Write(senddata4);UART1_Write(senddata4);delay_ms(1000);SPI1_Write(senddata5);UART1_Write(senddata5);delay_ms(1000);}while(1);}SLAVE CODE:/*SLAVE CODE*/sbit chipselect at RA5_bit;sbit chipselect_Direction at TRISA5_bit;sbit SDO at RC7_bit;sbit SDO_Direction at TRISC7_bit;sbit SDI at RB0_bit;sbit SDI_Direction at TRISB0_bit;sbit SCK at RB1_bit;sbit SCK_Direction at TRISB1_bit;short readdata;short readdata1;void main() {ADCON0 = 0x3C; // Disabling the ADC module which is multiplexed with SPI pinsADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pinsCMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pinsSPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexed with SPI pinschipselect_Direction=1;//SDI_Direction=1;//SDO_Direction=0;//SCK_Direction=1;UART1_Init(9600);delay_ms(200);SPI1_Init();delay_ms(100);do{readdata1=SPI1_Read(readdata);UART1_Write_Text(readdata1);readdata1=SPI1_Read(readdata);UART1_Write(readdata1);readdata1=SPI1_Read(readdata);UART1_Write(readdata1);readdata1=SPI1_Read(readdata);UART1_Write(readdata1);readdata1=SPI1_Read(readdata);UART1_Write(readdata1);}while(1);}Please help me -
AuthorPosts
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.