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
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
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Digilent Vivado library
- Teach you to learn 51 single chip microcomputer-C language version (Second Edition) (Song Xuefeng)
- Raspberry Pi Development in Action (2nd Edition) ([UK] Simon Monk)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University Hall ---- Image Processing and Analysis by Jia Yonghong, Wuhan University
- Weekly highlights: 2018.11.26-12.2
- 【Child care machine】+ ESP32S3-BOX network connection process record
- [GD32E503 Review] + Unboxing and Schematic Diagram
- In a battery-powered microcontroller product, when a pin is used for falling edge interrupt, how should this pin be set to achieve the most energy-efficient
- 【DIY Bing Dwen Dwen】+Bing Dwen Dwen with NFC function
- Urgently looking for a test engineer based in Beijing (preferably with some network security experience)
- Some measures to prevent digital circuits from being disturbed in single chip microcomputers
- Wireless communication solution for HMI control of crane feeding in copper processing workshop
- ADC conversion chip hx711