Monday, July 13, 2020

Introduction to ATMega32 SPI Application With SN74HC595N

Introduction to ATMega32 SPI serial peripheral interface

Serial Peripheral Interface Of Atmel AVR

The serial peripheral interface (SPI) is a high speed synchronous data transfer between a microcontroller (master device) and its peripheral device (slave). 

Introduction to ATMega32 SPI
A sample of program, show the text "SPI" on the SSD.


In some requirements, it's use to transfer data between a microcontroller (master) and others slave microcontrollers.

Introduction to ATMega32 SPI
The connection between a master and a slave device

For a master data transferring, it needs three wires:
  1. Master Out Slave In (MOSI), a master microcontroller send data out to the slave device.
  2. Serial Clock (SCK), a master microcontroller outputs
    synchronous clock while sending data out.
  3. Slave Select (SS), a master microcontroller issue a low logic level to force the slave device accepting the sent data. The SS pin could be any pin on the ATMega32 microcontroller when working as a master device.
In SPI communication, one different slave device requires it own slave select pin. So the number of slave devices increase the slave select pins.

Introduction to ATMega32 SPI
A sample of master transfer data. Clock is activated
from low to high. Data is transfer at rising edge
of clock. Slave select pin activate from high to
low to select the slave device.

In ATMega32, there some register to set up before the SPI is ready-to-use.

Introduction to ATMega32 SPI
SPI Control Register - SPCR

To use the SPI, set the SPE bit to '1' to turn on the SPI module.
The DODR is normally zero, allowing the data transfer the MSB first.
Setting the MSTR bit to '1', making the ATMega32 to work in master mode.
CPOL bit is the clock polarity select bit. It's zero by default and it's low in idle mode.
The CPHA is the clock phase setting bit. By default ( 0 ), the data is sample at the leading edge of the clock.
The clock rate select if Fosc/4 when it's not set.

Introduction to ATMega32 SPI
SPI Status Register

The SPI interrupt flag - SPIF uses for polling the completion of SPI transfer. It's set when the transfer is completed. The other bits are not discussed here.

Introduction to ATMega32 SPI
SPI Data Register
In master mode, writing data to the SPDR starts the transmission. In slave mode, reading this register when the reception is completed.

Programming Example In Atmel Studio 7 C

In this example I use the SPI module of ATMega32 to work in master mode. I use three slaves identical device, 74HC595 shift register. These three devices are the same in operation. So It requires only three wires. Activating the slave select pin once, these three shift register latch the data to its output register.

Introduction to ATMega32 SPI
A sample of program, show the text "SPI" on the SSD.

Source Code:


Introduction to ATMega32 SPI
Schematic diagram





We can also use the SN74HC164 serial to parallel shift registers chip to drive 7-Segment display in individual or multiplexing mode

ATMega32 SN74HC164 Three-Digit Multiplexing Display
Simulating Program

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)