|
|
|
|
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
November 20, 2009, 09:06:17 PM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Sept 30th - The
5th SoR Robot contest
is now open! Win an Axon II!
Robot Forum
72,665
Posts in
9,267
Topics by
5,290
Members
Latest Member:
robertelson
Robot Forum
>
Software
>
Software
>
HOW TO: SPI on Axon
0 Members and 1 Guest are viewing this topic.
Pages:
[
1
]
Author
Topic: HOW TO: SPI on Axon (Read 692 times)
sprince09
Jr. Member
Helpful? 0
Offline
Posts: 16
HOW TO: SPI on Axon
«
on:
March 04, 2009, 07:41:10 PM »
Hey guys,
I've been trying to get my Axon to interface with an SDCard (I need to do some data-logging) over the SPI interface. I read through the spi.c and spi.h files included in the latest source code for the Axon and I have been trying to use those functions to interface with my card. Going off of the pin labels in the Axon datasheet and a google search for the pinout of an SDCard, I'm fairly certain that I have my connections set up properly. Anyway, what I've noticed is that whenever I plug in my SDCard, the board resets continually until I remove, which indicates to me that I have a wiring problem somewhere, but I've rebuilt the circuit four times now, and I haven't been able to find any errors with that.
I guess what I'm really interested in knowing is if there are any special considerations I need to make when using SPI on the axon. I noticed that the hardware programmer uses the same pins (except for SS and reset) as SPI does... is there something I should be doing to account for that?
Relevant code that I am running:
void SPITest(void){
rprintfInit(uart1SendByte);
rprintf("\n\r");
spiInit();
rprintf("SPI Interface Successfully Initialized\r\n");
unsigned char a = 0;
while(1){
spiSendByte(a++);//this function blocks until register is cleared (won't clear if nothing is connected?)
rprintf("byte sent: %c \r",a);
}
}
Also, when I run the code without the SDCard attached, I get the initialization response over my UART "SPI Interface etc..." and then it blocks at spiSendByte(a++). My understanding of that function is that it will block until the data has been shifted out of the register (can't remember what register off the top of my head). I expected that it will block if the pin is unconnected (maybe I'm wrong).
Anyway, I'd appreciate any insight into this
EDIT: Read my next post!
«
Last Edit: March 13, 2009, 11:53:40 AM by sprince09
»
Logged
sprince09
Jr. Member
Helpful? 0
Offline
Posts: 16
Re: SPI woes (Axon)
«
Reply #1 on:
March 13, 2009, 11:47:35 AM »
Alright, after much frustration and self doubt I've figured out what was wrong. I ended up writing my own initialization function:
spi_init(void){
unsigned char a;
//setup pins
#define MISO PB3
#define MOSI PB2
#define SCK PB1
#define SS PB0
DDRB |= (1<<MOSI)|(1<<SCK)|(1<<SS);
DDRB &= ~(1<<MISO);
PORTB |= (1<<SS);//set SS high
PORTB &= ~(1<<MISO);//turn off internal pullup for MISO
PORTB &= ~(1<<MOSI);//pull MOSI low
PORTB &= ~(1<<SCK);//pull SCK low
//setup registers
SPSR = 0b00000000;//see datasheet
SPCR = 0b01010000;//see datasheet
//clear out any junk in SPI buffer
a = SPSR;
}
And the corresponding function for sending+receiving data:
unsigned char spi_transfer(unsigned char data){
//transmits data over SPI lines and returns the response
SPDR = data;
while(!(SPSR & (1<<SPIF)));//block untill data transmission/reception completes
return SPDR;
}
It turns out that setting up the software side of the interface wasn't my problem... it was the hardware. The axon_schematic.pdf labels the ISP programming headers (the SPI pins are also the programmer pins) as follows:
Left Right
VTG MISO
RST MOSI
GND SCK
However, the actual layout of the programming pins is:
Left Right
MISO VTG
SCK MOSI
RST GND
Works perfect for me now. Hope this helps anyone else who is having issues.
Logged
pomprocker
Supreme Robot
Helpful? 15
Offline
Posts: 1,411
Sorry miss, I was giving myself an oil-job.
Re: SPI woes (Axon)
«
Reply #2 on:
March 13, 2009, 11:52:10 AM »
Can you relabel this thread so that anyone searching for this problem in the future has an easier time finding it due to a more descriptive thread subject
Logged
Blog:
Nerd Stuff - Programming, Electronics, Mechanics
sprince09
Jr. Member
Helpful? 0
Offline
Posts: 16
Re: HOW TO: SPI on Axon
«
Reply #3 on:
March 13, 2009, 11:53:54 AM »
Updated
Logged
Pages:
[
1
]
Jump to:
Please select a destination:
-----------------------------
General Misc
-----------------------------
=> Misc
=> Robot Videos
-----------------------------
Software
-----------------------------
=> Software
-----------------------------
Electronics
-----------------------------
=> Electronics
-----------------------------
Mechanics and Construction
-----------------------------
=> Mechanics and Construction
Related Topics
Subject
Started by
Replies
Views
Last post
Axon
Electronics
gamefreak
5
1721
July 18, 2008, 09:28:26 PM
by
Admin
AXON
Electronics
jronald
20
3634
February 10, 2009, 04:35:35 PM
by
frodo
axon adc
Software
vidam
1
836
August 31, 2008, 06:58:11 PM
by
Admin
PWM on Axon
Software
mbateman
10
2923
March 23, 2009, 04:07:14 PM
by
Hanoush
Advertise on this Forum
Loading...