SPI multi-machine loop communication based on AVR microcontroller

Publisher:TechWhizKidLatest update time:2012-08-06 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Click to browse the next page
SPI communication with one master and three slaves The program is as follows: host://ICC-AVR application builder: 2012-1-13 18:56:57 // Target : M16 // Crystal: 8.0000Mhz // Complete program download: http://www.51hei.com/f/djhltl.rar #include #include #define Load_High PORTB|=(1<<4) #define Load_Low PORTB&=~(1<<4) unsigned char tab[]={0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; //Flowing light array /*------------------------------------------------ ------------------ Function name: void SPImasterInit(void) Function: SPI initializes as a master parameter: Return value: None SPI Control Register Introduction SPIE SPE DORD MSTR CPOL CPHA SPR1 SPR0 SPIE: Interrupt Enable SPE: SPI Enable DORD: Data order 1 is LSB first, 0 is MSB first MSTR: Master-slave selection 1 is master, 0 is slave. When MSTR is set, the host mode is selected, otherwise it is a slave. If MSTR is "1", If SS is configured as an input and is pulled low, MSTR is cleared and SPIF in register SPSR is set. The user must re- Set MSTR to enter master mode. CPOL: Clock polarity see ATMEGA16L (Chinese) P130 CPHA: Clock Phase SPR1, SPR0: SPI clock rate selection 1 and 0 SPR1 and SPR0 have no effect on the slave. -------------------------------------------------- ---------------*/ void SPImasterInit(void) //SPI initialization { DDRB|=(1<<7)|(1<<5)|(1<<4); //Set SCK, MOSI as output and others as input SPCR|=(1<8) { i=0; } Transmit(tab[i]); //Send data PORTC=SPDR; //The host receives the data from the slave and generates an action delay(100); } } Slave: #include #include //#include #define uchar unsigned char #define uint unsigned int void delay(uint ms) { uint i,j; for(i=0;i
Reference address:SPI multi-machine loop communication based on AVR microcontroller

Previous article:DS1302 adjustable perpetual calendar program based on ATMEGA16
Next article:Design of speech recognition system based on AVR microcontroller

Recommended ReadingLatest update time:2024-11-16 22:22

SPI four modes IO simulation timing
#include "iom8535v.h" #define _CPOL 1 #define _CPHA 0 #define SCK_IO DDRA|=0X01 #define MOSI_IO DDRA|=0X02 #define MISO_IO DDRA&=0XFB #define SSEL_IO DDRA|=0X08 #define SCK_D(X) (X?(PORT|=0X01):(PORT&=0XFE)) #define MOSI_D(X) (X?(PORTA|=0X02):(PORTA&=0XFD)) #define SSEL_D(X) (X?(PORTA|=0X08):(PORTA&=0XF7)) #defin
[Microcontroller]
HLK-W806 (IV): Software SPI and hardware SPI driver for ST7735 LCD
Introduction to ST7735 ST7735 is a TFT driver chip for driving up to 162x132 pixels, 396 (128*3 colors) x162 lines of output, which can be directly connected to an external controller via SPI protocol, or 8-bit/9-bit/16-bit parallel. Display data can be stored in the on-chip 132 x 162 x 18 bits memory, and the display
[Microcontroller]
HLK-W806 (IV): Software SPI and hardware SPI driver for ST7735 LCD
GigaDevice launches the first domestically produced high-speed 8-port SPI NOR Flash!
At the 9th Songshan Lake IC Forum held on May 10, Chen Hui, senior product marketing director of GigaDevice's storage division, said that GigaDevice has launched the first domestically produced high-speed 8-port SPI NOR Flash GD25LX256E, with a maximum clock frequency of 200MHz and a data throughput that is five times
[Mobile phone portable]
A method for realizing communication between DSP and other devices through SPI interface protocol
This paper introduces the SPI communication protocol, and focuses on the serial port configuration method and interface circuit design example when the TMS320C5402 DSP produced by TI is used for SPI protocol communication. Finally, the configuration program of the serial port McBSP is given. Keywords: multi-chann
[Industrial Control]
A method for realizing communication between DSP and other devices through SPI interface protocol
Simulate SPI implementation and debugging process
Generally speaking, all SPI communication devices can be implemented using analog SPI, and the advantage of analog SPI is that there is no need to re-familiarize yourself with the configuration of the SPI controller for each MCU. You only need to simply configure the input and output of the four pins SPI_CLK, SPI_Cs,
[Microcontroller]
MCU SPI module + 74LS164 driver digital tube
The effect is as follows: Circularly shift right and then left       #include htc.h #ifndef _XTAL_FREQ  #define _XTAL_FREQ 4000000 #endif const unsigned char seg_comAnode ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,                         0x07,0x7f,0x6f};//Common anode const unsigned char seg_comCathode ={0x
[Microcontroller]
MCU SPI module + 74LS164 driver digital tube
Design of Multi-channel Data Acquisition System Based on SPI Bus
    With the development of microprocessors and their wide application in various fields, people have put forward higher and higher requirements for electronic measurement technology and electronic instrument systems, and the requirements for test speed and accuracy are also increasing day by day. The test system main
[Microcontroller]
Design of Multi-channel Data Acquisition System Based on SPI Bus
STM32F103 SPI3 Summary
Recently, I used STM32F013RCT6 to debug the NRF24L01 module, with a total of three SPI channels, connecting three 2.4G modules. There is no problem with SPI1 and SPI2, and the check can pass. Use the same method to configure SPI3, but the check fails. I checked the pin configuration and wiring sequence several t
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号