Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me !! SPI assembler for AVR

Status
Not open for further replies.

lawson

Newbie level 4
Joined
Nov 8, 2009
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Vietnam
Activity points
1,327
help me !! SPI assembler

hi everybody i'm beginning learning to program the AVR SPI with assembly ,but it can't transmit data to PORTC at the slave SPI ,help me,please!!
;*****************MASTER SPI*****************
;*************************************
; DECLARE MASTER SPI :
LDI R16,(1<<DDB2)|(1<<DDB3)|(1<<DDB5)
OUT DDRB,R16
LDI R17,(1<<SPIE)|(1<<SPE)|(1<<MSTR)
OUT SPCR,R17

;*************************************

MAIN:
IN R19,PINC
RCALL SEND
RJMP MAIN
SEND:
OUT SPDR,R19
Wait:
sbis SPSR,SPIF
rjmp Wait
RET

;***************** SlAVE SPI*****************
;*************************************
;DECLARE SLAVE SPI:
LDI R16,(1<<DDB3)
OUT DDRB,R16
ldi R17,(1<<SPE)
out SPCR,R17
;*************************************
MAIN:
RCALL RECEIVE
OUT PORTC,R16
RJMP MAIN

RECEIVE:
sbis SPSR,SPIF
rjmp RECEIVE
IN R16,SPDR
RET
 

help me !! SPI assembler

Hi,
In Slave SPI program:
It should be:
Code:
LDI R16,(1<<DDB4)
OUT DDRB,R16
You have to use the MISO pin for input, not MOSI.
And in the master SPI program, you've set the SPI Interrupt, but you have no interrupt service routine. You don't need to enable interrupt.
So, it should be:
Code:
LDI R17,(1<<SPE)|(1<<MSTR)
Hope this helped.
Let me know if it worked.
Tahmid.
 

Re: help me !! SPI assembler

Thank! Tarmid but it can't go , i fogot saying you that i use the atmega8 ,and when i export data into PORT C at slave SPI,it is always at high,although i changed the transmited data with PINC at master SPI ,can you help me ??:D

Added after 57 minutes:

if i want to use interrupt what i have to do
 

help me !! SPI assembler

Hi,
I think your code (without interrupt) should be:
Code:
;*****************MASTER SPI*****************
;*************************************
; DECLARE MASTER SPI :
LDI R16,(1<<DDB2)|(1<<DDB3)|(1<<DDB5)
OUT DDRB,R16
LDI R17,(1<<SPIE)|(1<<SPE)|(1<<MSTR)
OUT SPCR,R17

;*************************************

MAIN:
IN R19,PINC
SBI PORTB,2
RCALL SEND
RJMP MAIN
SEND:
CBI PORTB,2
OUT SPDR,R19
Wait:
sbis SPSR,SPIF
rjmp Wait
SBI PORTB,2
RET

;***************** SlAVE SPI*****************
;*************************************
;DECLARE SLAVE SPI:
LDI R16,(1<<DDB4)
OUT DDRB,R16
ldi R17,(1<<SPE)
out SPCR,R17
;*************************************
MAIN:
RCALL RECEIVE
OUT PORTC,R16
RJMP MAIN

RECEIVE:
sbic PORTB,2
RJMP RECEIVE
sbis SPSR,SPIF
rjmp RECEIVE
IN R16,SPDR
RET

Added after 53 seconds:

I can try to provide code with interrupt if desired, but try the given code first. I think it should work.
Hope you notice and understand the changes.
Hoping it helped.
Tahmid.
 

Re: help me !! SPI assembler

thanks!! i did it ,you are a pro programmer !! ah ,can you give me your nickname ?, i have begun learning the assembly ,so there are a lot of knowledge that i dont know . i want to improve it ,can you help me!!
 

help me !! SPI assembler

Hi,
Well, I'm not very good with AVR in assembly language. I use mikroBASIC but if you get stuck, I can try to help.
Nickname? I don't get what you mean by this.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top