AVR Assembler, Serial Peripheral Interface (SPI), 2 x ATmega328P

AVR Assembler, Serial Peripheral Interface (SPI), 2 x ATmega328P
  1. Arduino UNO
/************************************************** ****** ****** MASTER CODE ****** **************************************************/ .nolist .include "./m328Pdef.inc" .list .def temp = r16 .equ PSPI_SCK = 5 .equ PSPI_MISO = 4 .equ PSPI_MOSI = 3 .equ PSPI_SS = 2 .org 0x0000 rjmp start .org 0x0022 rjmp SPI_STC ; SPI Transfer Complete start: clr temp out ddrd, temp ser temp out portd, temp cbi ddrc, 0 sbi portc, 0 ldi temp, high(RAMEND) out sph, temp ldi temp, low(RAMEND) out spl, temp ldi temp, (1<<PSPI_SCK)|(1<<PSPI_MOSI)|(1<<PSPI_SS) out ddrb, temp sbi portb, PSPI_SS sbi portb, PSPI_MISO ldi temp, 0 ori temp, (1<<SPIE) ; SPI0 Interrupt Enable ori temp, (1<<SPE) ; SPI0 Enable ori temp, (1<<MSTR) ; Master/Slave Select ori temp, (1<<SPR0) ; fosc/16 out SPCR, temp sei loop: sbis pinc, 0 rcall post rjmp loop SPI_STC: cli nop sei reti post: sbi portb, PSPI_SS cbi portb, PSPI_SS ; start spi in temp, pind com temp out SPDR, temp sbi portb, PSPI_SS ; stop spi ret /************************************************** ****** ****** SLAVE CODE ****** **************************************************/ .nolist .include "./m328Pdef.inc" .list .def temp = r16 .equ PSPI_MISO = 4 .org 0x0000 rjmp start start: ldi temp, high(RAMEND) out sph, temp ldi temp, low(RAMEND) out spl, temp ser temp out ddrc, temp ldi temp, 0 ori temp, (1<<PSPI_MISO) out ddrb, temp ; Enable SPI ldi temp, (1<<SPE) out SPCR, temp loop: rcall SPI_SlaveReceived rjmp loop SPI_SlaveReceived: ; Wait for reception complete in temp, SPSR sbrs temp, SPIF rjmp SPI_SlaveReceived ; Read received data and return in temp,SPDR out portc, temp ret