The problem of ATmega168's SPI sending register SPIF not being set

Publisher:快乐飞翔Latest update time:2020-03-04 Source: eefocusKeywords:ATmega168 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Use the ATmega168 hardware SPI driver 74HC595 to expand the serial interface. Set MOSI and SCK to output, and then set the registers. , as follows:


static void vSpi595Init(void)


{


DDRB|=(1<


DDRD|=(1<


SPCR=(1<


}


Then call the following send function


static void vSPIMasterTransmit(unsigned char ucData)


{


SS_L(); //Pull down the storage register clock


SPDR = ucData; // Start data transmission


while(!(SPSR & (1<


SS_H(); //Pull up the storage register clock


}


But I found that the SPIF interrupt was not generated. Replacing the chip, adjusting the clock and SPI rate did not work.


Later I searched on ouravr website and found that many people encountered the same problem, and someone gave a solution. It is necessary to set the SS pin to output.


The modified initialization function is


static void vSpi595Init(void)


{


DDRB|=(1<


DDRD|=(1<


SPCR=(1<


}


That is to say, when acting as a host, SS must be set to output, and after the chip is reset, the SS pin defaults to input, so it must be actively set in the program. It seems that this is not clearly stated in the datasheet.

Keywords:ATmega168 Reference address:The problem of ATmega168's SPI sending register SPIF not being set

Previous article:Design of pure hardware circuit of intelligent car control system based on ATmega16
Next article:Design of electro-hydraulic servo valve feedback controller based on ATmega16

Recommended ReadingLatest update time:2024-11-16 17:38

ATmega168 Power-On Reset
The power-on reset (POR) pulse is generated by the on-chip detection circuit. The detection level is shown in Table 20. Whenever VCC falls below the detection level, a POR occurs. The POR circuit can be used to trigger a reset or to detect a power failure. The POR circuit ensures that the device is reset at power-on
[Microcontroller]
ATmega168 Power-On Reset
Understanding the SSM and SSI bits of the SPI_CR1 register of STM32
I recently debugged the SPI program of STM32, and now I record my little understanding.   Understanding the SSM and SSI bits of the SPI_CR1 register of STM32      SSM bit, enables or disables software slave selection. When SSM is set, the level of the NSS input pin will be replaced by the value of SSI.      The
[Microcontroller]
AVR MCU SPI Example (mega8515)
The interrupt method is used to realize full-duplex communication.  This example uses two MEGA8515s, and the connection is:  MISO----MISO  MOSI----MOSI  SCK ----SCK  /SS ----/SS  The function fill_tx_buffer that loads the data to be sent into the send buffer  and the function read_rx_buffer that reads the data from th
[Microcontroller]
Use SPI interface to realize dual DSP bidirectional communication and synchronization
Abstract: In order to realize the bidirectional data communication and synchronization between two TMS320F2812 DSPs, the hardware circuit design and software protocol implementation scheme of using the serial SPI peripheral interface module integrated inside the TMS320F2812 DSP to realize the bidirectional dat
[Embedded]
Use SPI interface to realize dual DSP bidirectional communication and synchronization
[STC15 library function hands-on notes] 9. Hardware SPI
STC Experiment Box 4 IAP15W4K58S4 Keil uVision V5.29.0.0 PK51 Prof.Developers Kit Version:9.60.0.0 Hardware knowledge        Excerpted from "STC15 Series MCU Device Manual"        The STC15 series microcontrollers also provide another high-speed serial communication interface - SPI interface. SPI is a full-duplex, h
[Microcontroller]
[STC15 library function hands-on notes] 9. Hardware SPI
C language programming of synchronous serial port spi
#include #include macros.h #define uchar unsigned char #define uint unsigned int uchar Table ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; uchar Da ta ={0,0,0,0}; void DelayMs(uint i)  {uchar j; for(;i!=0;i--) {for(j=2000;j!=0;j--) {;}} } void Display(uchar *p) {uchar i,sel=0x01; for(i=0;i 4;i+
[Microcontroller]
STM32F10X SPI operation flash MX25L64 read and write data
  A simple application, ARM chip as master, flash as slave, to achieve one-to-one communication. ARM master chip STM32F103, flash chip is MX25L6465E of MACRONIX INTERNATIONAL, 64Mbit.   SPI should be the simplest application in embedded peripherals! There are two general methods for SPI application: software simulatio
[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号