EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Unable to implement SPI communication using mikroc library

Unable to implement SPI communication using mikroc library

|

Microcontroller › PIC › Unable to implement SPI communication using mikroc library

  • This topic has 0 replies, 1 voice, and was last updated 9 years, 3 months ago by umair.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • September 8, 2016 at 1:11 pm #4553
    umair
    Participant

    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 pins
         ADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pins
         CMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pins
         SPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexed with SPI pins
         chipselect_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 pins
         ADCON1 = 0x0F; // Disabling the ADC module which is multiplexed with SPI pins
         CMCON = 0x00; // Disabling the COMPARATOR module which is multiplexed with SPI pins
         SPPCON = 0x00; // Disabling the SERIAL PERIPHERAL CONTROL module which is multiplexed with SPI pins
         chipselect_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

     

  • Author
    Posts
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • What is involved to convert a small town to fiber optic? December 11, 2025
  • volkswagen car stereo model rcd310 December 11, 2025
  • Dog fence help December 11, 2025
  • anyone recognizes this laser diode? December 10, 2025
  • How to power motors for lumbar support? December 10, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise