Pages: [1]   Go Down
Author Topic: LED Diplay in different digital ports  (Read 483 times)
0 Members and 1 Guest are viewing this topic.
Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I used three four-digit, seven-segment LED display that has an SPI interface to show some numbers on them.
http://tronixstuff.wordpress.com/2011/05/13/tutorial-arduino-and-the-spi-bus/
I used the code below, and all went fine.

Now I'm trying to move data pins between D2 and D7 (I need to expand my project adding a shield that use ports from D8 to D13).
I tried many changes, but it seems when I move SPICLOCK from D13 to any other, all doesn't work.

What's wrong?
Thanks.

Andrea

Code:
/*
 Example 34.3 - SPI bus demo using SFE 4-digit LED display [http://bit.ly/ixQdbT]
 http://tronixstuff.com/tutorials > chapter 34
 Based on code by Quazar & Busaboi on Arduio forum - http://bit.ly/iecYBQ
*/

/*
WIRING
Board GND to Arduino GND
Board VCC to Arduino 5V
Board SCK to Arduino D13
Board SI to Arduino D11
Board CSN to Arduino Dx
*/

#define DATAOUT 11 //MOSI
#define SPICLOCK 13 //sck
#define SLAVESELECT1 8 //ss1
#define SLAVESELECT2 9 //ss2
#define SLAVESELECT3 10 //ss3

char spi_transfer(volatile char data)
{
  SPDR = data;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  return SPDR;                    // return the received byte
}

void setup()
{
  byte clr;
  pinMode(DATAOUT, OUTPUT);
  pinMode(SPICLOCK, OUTPUT);
  pinMode(SLAVESELECT1, OUTPUT);
  pinMode(SLAVESELECT2, OUTPUT);
  pinMode(SLAVESELECT3, OUTPUT);
  digitalWrite(SLAVESELECT1, HIGH); //disable device
  digitalWrite(SLAVESELECT2, HIGH); //disable device
  digitalWrite(SLAVESELECT3, HIGH); //disable device
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1);
  clr=SPSR;
  clr=SPDR;
  delay(10);
  write_led_numbers(0x78,0x78,0x78,0x78,SLAVESELECT1); //Blank display
  write_led_numbers(0x78,0x78,0x78,0x78,SLAVESELECT2); //Blank display
  write_led_numbers(0x78,0x78,0x78,0x78,SLAVESELECT3); //Blank display
  write_led_decimals(0x00,SLAVESELECT1); // All decimal points off
  write_led_decimals(0x00,SLAVESELECT2); // All decimal points off
  write_led_decimals(0x00,SLAVESELECT3); // All decimal points off
 
  delay(500);
  write_led_numbers(1,1,1,1,SLAVESELECT1);
  delay(500);
  write_led_numbers(2,2,2,2,SLAVESELECT2);
  delay(500);
  write_led_numbers(3,3,3,3,SLAVESELECT3);
  delay(500);
  write_led_numbers(9,9,9,9,12); 
}

void write_led_decimals(int value, int slave)
{
  digitalWrite(slave, LOW);
  delay(10);
  spi_transfer(0x77);     // Decimal Point OpCode
  spi_transfer(value);    // Decimal Point Values
  digitalWrite(slave, HIGH); //release chip, signal end transfer
}
void write_led_numbers(int digit1, int digit2, int digit3, int digit4, int slave)
{
  digitalWrite(slave, LOW);
  delay(10);
  if(digit1)
    spi_transfer(digit1);    // Thousands Digit
  else
    spi_transfer(0x78);    // Thousands Digit
 
  spi_transfer(digit2);    // Hundreds Digit
  spi_transfer(digit3);    // Tens Digit
  spi_transfer(digit4);    // Ones Digit
  digitalWrite(slave, HIGH); //release chip, signal end transfer
}

void loop()

}

Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 36
Posts: 4303
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I tried many changes, but it seems when I move SPICLOCK from D13 to any other, all doesn't work.

What's wrong?
The SPI interface uses a hardware subsystem built into the microprocessor.  Several of the pins are fixed and cannot be changed.  

The only way around this would be to use a 'Soft SPI' library.


Don
Logged

Italy
Offline Offline
Newbie
*
Karma: 0
Posts: 14
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Don.

I will take a look to that library.

Andrea
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 534
Posts: 26970
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

"adding a shield that use ports from D8 to D13"
Does that shield also use SPI?
If so, both devices will connect D11-12-13, and each will need unique SS pins.

Code:
#define SLAVESELECT1 8 //ss1
#define SLAVESELECT2 9 //ss2
#define SLAVESELECT3 10 //ss3
These can go to your other pins.

Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1]   Go Up
Jump to: