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 / Software SPI using C

Software SPI using C

|

Microcontroller › 8051 › Software SPI using C

  • This topic has 2 replies, 3 voices, and was last updated 7 years, 10 months ago by sharon.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • April 30, 2017 at 5:12 am #4651
    S Ganesh
    Participant

    Hi I am creating software SPI on AT89C4051 which sends LSB first. But i is not giving required output only SCK line is going HI and Low

    below is my code. I have implimented SPI write. Not used Slave Select because its not required for my application.

    #include <REGx051.H>

    sbit MISO = P1^0;

    sbit MOSI = P1^7;

    sbit  SCK = P1^6;
     
    unsigned int i,j;
    char temp, Data[10];
     
    void delay_ms(unsigned int time);
    void SCK_HiLow();
    void SPI_write();
     
    void main()
    {
    delay_ms(100); 
    MISO = 1;          //Make input port
    MOSI = 0;          //Make ouput port
    SCK  = 0;          //Mack SCK idle
     
    Data[5] = 0xAA;
    Data[6] = 0xF0;
    Data[7] = 0x0F;
    Data[8] = 0x55;
     
    SPI_write();
    while(1);
    }      //End of Main
     
     
    void delay_ms(unsigned int time)
           {
              for(i = 1; i<= time; i++)
                  {
                      for(j = 1; j<= 111; j++);
                  }
           }
     
    void SPI_write()         //send through MOSI
       {
           for(j = 5; j <= 8; j++)
              {
                 for(i = 8; i != 0; i–)                    //Send 8-bit
                     { 
                        temp = Data[j];
                        P1 = 0x80 & (0x7F | (temp << i)); 
     //Shift to get LSB to send first. Write on P1.7 keeping all other bits 0
                        SCK_HiLow();                                         
                     }
               }
       }
     
    void SCK_HiLow()
    {
         SCK = 1;
         delay_ms(10);
         SCK = 0;
         delay_ms(20);
    }

     

    May 1, 2017 at 7:19 am #14586
    Ashutosh Bhatt
    Participant

    why you want SPI using 89C4051

    use any micro controller with built in SPI like ARM, AVR PIC etc

    June 1, 2018 at 11:47 am #14836
    sharon
    Participant

    The C-code described below has been compiled for the MAXQ2000 microcontroller, which is used on the MAX7456 evaluation (EV) kit. The complete set of software routines is available in this application note. The routines are self-documenting, so little additional description is provided. The C-Code below is also available in the following files: spi.c and MAX7456.h

    The code uses the standard nomenclature for the SPI lines. The MAXQ2000 processor is the SPI master and the MAX7456 is the SPI slave.

    CS is the same as is used in the MAX7456 data sheet.
    SDIN is referred to as MOSI (master out slave in).
    SDOUT is referred to as MOSI (master in slave out).
    SCLK is referred to as CK.

    http://www.cetpainfotech.com/technology/embedded-system

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

RSS Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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