Help with MAX6954 disp. driver

Hello to all!
I’m trying to interface arduino with the max6954 disp. driver. It’s the first time that i use SPI, and i’m experiencing big problems writing the code. I’ve modified the source of the “SPI EEPROM TUTORIAL”…but i’m seriously thinking that i’ve made errors;
I’m searching to activate the display test mode, writing 16 bits of data in a dedicated reg.
Test contains the address of the reg(first 8 bits), and the data to write.

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

//opcodes
#define TEST  0000011100000001


byte clr;



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()
{
  Serial.begin(9600);

  pinMode(DATAOUT, OUTPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  // SPCR = 01010000
  //interrupt disabled,spi enabled,msb 1st,master,clk low when idle,
  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  
}
void loop()
{
  digitalWrite(SPICLOCK,LOW);
  digitalWrite(SLAVESELECT,LOW);
  spi_transfer((char)(TEST>>8));   //send MSByte address first
  spi_transfer((char)(TEST));      //send LSByte address
  digitalWrite(SPICLOCK,LOW);
  digitalWrite(SLAVESELECT,HIGH);
  digitalWrite(SLAVESELECT,LOW);
  Serial.print('i',BYTE);
  Serial.print('\n',BYTE);//debug
  delay(3000);
}

Please, someone help me!!
Thanks in advance!

Hi,

I’ve been doing a bit with SPI and another IC (an 8-bit I/O expander) so thought I’d point out a couple of things I noticed that may or may not help.

I’ve got my (in progress) notes here: Learning About Arduino with MCP23S08 - LearningAboutArduinoMCP23S08 and you can find my current code in the “Progress” section.

//opcodes

#define TEST  0000011100000001

AFAIK this will define a large number, not a value in binary. From memory the Arduino environment only defines B00000000 to B11111111 as their binary equivalents so you’ll need to make TEST defined as the MSB (most-significant-byte) shifted left 8-bits plus the LSB, or simply define TEST_MSB B00000111 and TEST_LSB B00000001.

  //sample on leading edge of clk,system clock/4 rate (fastest)
  SPCR = (1<<SPE)|(1<<MSTR);

You need to check if the specifications for your IC match this configuration.

  digitalWrite(SPICLOCK,LOW);

I have no idea if this actually does anything, but once you’ve set the SPICLOCK pin as an output the actual clock is controlled by hardware so you don’t need to touch it. Remove all your digital writes to the SPICLOCK pin.

  digitalWrite(SLAVESELECT,HIGH);
  digitalWrite(SLAVESELECT,LOW);

Why do you put the SLAVESELECT low again? I think this is an error.

Hope this is of some use.

Thanks for the message, I think that my problem is that i did not understand the way to send a word(16 bit) in one time.... I checked the parameters of the chip (Max6954) and all seems fine, and i have erased the "manual digitalwrite" of the pins...but....nothing work.... I'm thinking to buy a logical analyzer...so i can do a deepest debug..... :( Please, help me!! :)

Hi:

I think you might have a problem with these lines. If you are going to send 2 bytes, I think TEST should be split into TESTMSB and TESTLSB in your define.

spi_transfer((char)(TEST>>8)); //send MSByte address first
spi_transfer((char)(TEST)); //send LSByte address

The 6954 wants MSB 1st, so bit 16. I think it should be << to shift left. With TEST split it would look like:

spi_transfer((char)(TESTMSB<<8)); //Send MSB starting at bit 16 and counting down
spi_transfer((char)(TESTLSB<<8)); //Send LSB starting at bit 8 and counting down

Hope I’m not steering your wrong. I did a bunch of work with the 7219 and this is what I did to get it to go in Basic. I’m working on the 6954 for the Arduino now too.

TimV