Home » Source Code » SPI Header File for AVR (Written for ATmega128, but it should work for other AVR's too)

SPI Header File for AVR (Written for ATmega128, but it should work for other AVR's too)

agolia14
2016-07-04 00:11:37
The author
View(s):
Download(s): 0
Point (s): 1 

Description

It is a generalized SPI header file written for AVR with several configurable options. For configuring the options you need to make changes in the C source file. At present the header file is suitable only for Hardware SPI. I will update the same for software SPI too after some time. I have tried to make the header file readable but still if anyone faces any issue please ping me. I will reply as soon as I come online. Any suggestions are welcome too as I am posting my header files ol for the first time.


Here is a quick review of the functions in the header file:-

  1. void spi_init();
    Used to initialize SPI bus. the default values are already defined in the source file. If you need to change any of the configuration parameters just make changes in the source file.

  2. void spi_write(char*,uint8_t);
    Used to write data on the SPI bus. In the first parameter you need to pass a pointer to the char array. In second parameter you need to pass the length of the array.

  3. char* spi_read(uint8_t);
    Used to read data from the SPI bus. The length of data to be read is specified as argument and a char pointer pointing to the address of the first read byte is returned through it.


For setting the pins used for SPI following macros can be used:-


  1. #define SPI_PORT PORTB
    Set the port which will be used for the SPI Communication
  2. #define SPI_DIR DDRB
    Set  the Data direction register of the Port used for SPI Communication
  3. #define SS 0
    The pin number on SPI Port which will be used as SS
  4. #define MISO 3
    The pin number on SPI Port which will be used as MISO
  5. #define MOSI 2
    The pin number on SPI Port which will be used as MOSI
  6. #define SCK 1
    The pin number on SPI Port which will be used as SCK

Your Suggestions are simply welcome


Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
spi.h668.00 B04-07-16|09:38
basic.h359.00 B05-06-16|19:51
SPI0.00 B44%|04-07-16
spi.c6.56 kB04-07-16|09:37
...
Sponsored links

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
  • 1
  • Page 1
  • Total 1

SPI Header File for AVR (Written for ATmega128, but it should work for other AVR's too) (3.18 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D