Wenn es heißt: "Wenn SS High ist, dann ist der Device NICHT selected".
Aber was genau heißt hier high? Ich messe nur 0,03V und 0.07A wenn ich
den pin auf High schalte.. soll das so sein?
Ich hab überhaupt ziemliche Probleme beim Nachvollziehen was das
Datasheet genau von mir will ..
http://akizukidenshi.com/download/ATMEGA8-16PU-ND.pdf
ATmega8 Main:
1 | #define F_CPU 8000000UL
|
2 |
|
3 | #include <avr/io.h>
|
4 | #include <util/delay.h>
|
5 |
|
6 | #include <spi.h>
|
7 | #include <mcp23s17.h>
|
8 |
|
9 | int main (void)
|
10 | {
|
11 | DDRB = 0xFF;
|
12 |
|
13 | Spi_InitializeAsMaster();
|
14 |
|
15 | Mcp23s17 mcp;
|
16 | Mcp23s17_Initialize(&mcp, &PORTB, PB2);
|
17 |
|
18 | while(1)
|
19 | {
|
20 | }
|
21 | }
|
SPI Header:
1 | #ifndef SPI_H_
|
2 | #define SPI_H_
|
3 |
|
4 | #define SPI_MOSI PB3
|
5 | #define SPI_SCK PB5
|
6 |
|
7 | typedef struct {
|
8 | volatile int * sfr_address;
|
9 | int sfr_pin;
|
10 | } Spi;
|
11 |
|
12 | #define SPI_UNSELECT(s) *((Spi*)&(s))->sfr_address = *(((Spi*)&(s))->sfr_address) | (1 << ((Spi*)&(s))->sfr_pin);
|
13 | #define SPI_SELECT(s) *((Spi*)&(s))->sfr_address = *(((Spi*)&(s))->sfr_address) & (0xFF ^ (1 << ((Spi*)&(s))->sfr_pin));
|
14 |
|
15 | void Spi_InitializeAsMaster(void);
|
16 |
|
17 | #endif /* SPI_H_ */
|
ATmega8 als Master initalisieren:
1 | #include <spi.h>
|
2 | #include <avr/io.h>
|
3 | #include <util/delay.h>
|
4 |
|
5 | void Spi_InitializeAsMaster(void)
|
6 | {
|
7 | // Set PB3/MOSI and PB5/SCK output, all others input
|
8 | DDRB = (1 << SPI_MOSI) | (1 << SPI_SCK);
|
9 |
|
10 | // Enable SPI, Master, set clock rate fck/16
|
11 | SPCR = (1 << SPE) // SPI enable
|
12 | | (1 << MSTR) // Master/Slave select
|
13 | | (1 << SPR0); // SPI clock rate select
|
14 | }
|
MCP23S17 Initialisierung:
1 | #include <mcp23s17.h>
|
2 | #include <avr/io.h>
|
3 |
|
4 | void Mcp23s17_Initialize(Mcp23s17 *self, int * sfr_address, int sfr_pin)
|
5 | {
|
6 | self->spi.sfr_address = sfr_address;
|
7 | self->spi.sfr_pin = sfr_pin;
|
8 | SPI_UNSELECT(self->spi)
|
9 | }
|