SPI handling sample code (AVR)

Nov 17, 2004 1 Replies

Hello, All!



Where it's possible to get some simple source code in C controlling SPI communication? I need to understand master/slave init, transfer, etc. I've checked datasheet for my MCU but code presented there seems to be too easy :) Thanks in advance.



With best regards, Roman Mashak. E-mail: snipped-for-privacy@tusur.ru


SPI

SPI is very simple, usually all you have to do is to write the byte you want to send into a register, wait for a xfer done bit to become set, and read the received data from a register.

The difficulties are in the periphals you want to control and making sure you have selected the right SPI mode from the numerous modes there are (clock phase, clock edge select, msb/lsb first etc). Some devices support full duplex, some don't.

So, SPI in itself is very easy, but some devices can have many registers to setup before they can be used.

Jeroen

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required