Using SDPR Register right


I am trying to control a 7-Segment Display using the Arduino Uno and the MCP23S17.

This is my Code so far( not sure tho if this is correct):

#define F_CPU 16000000UL
#include <avr/io.h>
#include <SPI.h> 

#define DATAOUT 11//MOSI
#define DATAIN  12//MISO
#define SPICLOCK  13//sck
#define SLAVESELECT 10//ss

int main(void)
  PORTB = (1<<2); // Pull-Up-Widerstand
  DDRB = (1<<2);
  DDRD |= (0<< DATAIN); //schalte Pin 12 auf Eingang
  DDRD |= (1<<SLAVESELECT) | (1<< SPICLOCK) | (1<<DATAOUT); //Pin 10,13, 11 werden auf Ausgang gesetzt
  SPI_CLOCK_DIV64;   //Takt 64


Now I am trying to store a byte in the SDPR register and wait until it got send.
However do I have no idea how to do this. I've been researching all morning but I seem to not find the right answer. To be honest I don't know anything about the SDPR, where it is, what it does, how I can use it.

I hope one of you might be able to help me out.

It looks like you are not using the SPI library to the full extent possible, which proper use might mean you would be doing neither direct port manipulation nor worrying about some (obscure?) register.

If you just want to transfer data between the Arduino and some SPI device, use the SPI library. See some simple SPI examples.


Your display is not wired correctly. You need 8 X 330R, one for each segment. There should be no resistor on the common pin.

Works with the older AVRs with SPI

uint8_t spi_write(uint8_t data)
	uint8_t rtn = 0;

	SPDR = data;
	while((SPSR & SPIF_bm) == 0);
	rtn = SPDR;

	return rtn;

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.