Microcontroller › 8051 › Software SPI using C
- This topic has 2 replies, 3 voices, and was last updated 6 years, 8 months ago by
sharon.
-
AuthorPosts
-
April 30, 2017 at 5:12 am #4651
S Ganesh
ParticipantHi 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 portMOSI = 0; //Make ouput portSCK = 0; //Mack SCK idleData[5] = 0xAA;Data[6] = 0xF0;Data[7] = 0x0F;Data[8] = 0x55;SPI_write();while(1);} //End of Mainvoid 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 0SCK_HiLow();}}}void SCK_HiLow(){SCK = 1;delay_ms(10);SCK = 0;delay_ms(20);}May 1, 2017 at 7:19 am #14586Ashutosh Bhatt
Participantwhy 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 #14836sharon
ParticipantThe 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. -
AuthorPosts
- You must be logged in to reply to this topic.