LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Hardware SPI Setup

I am using LVIFA and I have added some new commands.

I'm attempting to use LVIFA with lpd6803 LED current driver. I'm starting simple.

I have one command that inits my setup and some commands that do some basic color displays that I have tested with just Arduino.

The problem seems to be my Init function.

It appears to lock up the LVIFA (on the arduino side LV still is running fine)

I'm trying to identify what function is screwing it up. It is using Hardware SPI and I am worried that might be the culprit.

Any ideas?

0 Kudos
Message 1 of 6
(5,062 Views)

You added new commands in LabVIEW or in the firmware?  It's hard to help without the code and the error.

0 Kudos
Message 2 of 6
(3,694 Views)

Haha alright, I'll attach some code.

First is the excerpt where I modified the firmware.

Next, is the init function an some of the functions it calls.

When I put BL.init() in my setup function, the LVIFA serial fails when I start LVIFA.

When I moved it to a command, it obviously allows me to connect.

However, I can't seem to get the code to execute (as I know it does when in a sketch by itself) but I don't get a serial error in LV.

If I can provide something else useful, let me know!


/*********************************************************************************

** Light Controls

*********************************************************************************/
  case 0x35:  // Init
    BL.setLeds(NUM_LEDS);               // Initialisation functions
    BL.init();                          // SPI interrupt will now send out data to LEDs. This happens in the background, pretty fast.
   
    BL.gridHeight=5;                    // Grid dimensions for LINE and BOX effect functions are defined here. Also used for Spectrum Analyzer function.
    BL.gridWidth=11;
    blank();  
  break;
 
  case 0x36:  // Color Up Red
    ColorUp(BL.color(31,0,0));
  break;
 
  case 0x37:  // Color Up Green
    ColorUp(BL.color(0,0,31));
   
  break; 
  case 0x38:  // Color Up Blue
    ColorUp(BL.color(0,31,0));
  break;

Here are some vars that are used:

#if defined(__AVR_ATmega328P__)

#define SPI_PORT PORTB

#define SPI_DDR  DDRB

#define SPI_PIN  PINB

#define SPI_MOSI 3       // Arduino pin 11.

#define SPI_MISO 4       // Arduino pin 12.

#define SPI_SCK  5       // Arduino pin 13.

#define SPI_SSN  2       // Arduino pin 10.

#define DATA_PIN 11

#define SLAVE_PIN 12

#define CLOCK_PIN 13

#define LATCH_PIN 10

here is blip.init

void CBLIP_LEDS_SPI::init()                 // Initialisation Function

{


  pData = m_pDataEnd;

  setup_hardware_spi();          

 

  unsigned int Counter;

  for(Counter = 1; Counter<NUM_LEDS; Counter++)

  {


setPixel(Counter, 0x80);

  }

  Display=(unsigned int *) m_pData; 

  sei(); 

  SPDR = 0x00;

}

void CBLIP_LEDS_SPI::setup_hardware_spi(void)    
{  

  pinMode(DATA_PIN,OUTPUT);                   // Pin Setup of specified hardware                    

  pinMode(LATCH_PIN,OUTPUT);

  pinMode(CLOCK_PIN,OUTPUT);

  pinMode(SLAVE_PIN,OUTPUT);

  digitalWrite(DATA_PIN,LOW);

  digitalWrite(LATCH_PIN,LOW);

  digitalWrite(CLOCK_PIN,LOW);

  digitalWrite(SLAVE_PIN,LOW);

  // SPI prescaler:

  // SPI2X SPR1 SPR0

  //   0 0 0fosc/4
  //   0 0 1fosc/16
  //   0 1 0fosc/64
  //   0 1 1fosc/128             
  //   1 0 0fosc/2                << Set in this instance                 
  //   1 0 1fosc/8
  //   1 1 0fosc/32
  //   1 1 1fosc/64

 

  SPCR |= ( (1<<SPE) | (1<<MSTR) | (1<<SPIE) ); // enable SPI as master

  SPCR &= ~( (1<<SPR1) | (1<<SPR0) );       // clear prescaler bits

  SPSR |= (1<<SPI2X);

}

0 Kudos
Message 3 of 6
(3,694 Views)

***Edit***

I attempted some basic serial to serial communication (pulling all of the overhead of LVIFA out of the frame) and I had some issues getting that working. I think that may be my solution in the end. I think that LVIFA may have been too much over-head anyways.

I don't think that is appropriate for this post. I'm moving it over to the Arduino posts for communication. This post is about figuring out what portion of the LVIFA code is interfering with the Blip code or vice versa.

-------

That being said, here is what I've attempted:

1. Dug through all of the LVIFA and Blip drivers looking for peripherals or ISR's that are used reduntantly. I coudln't find any.

2. Looked for pieces of LVIFA that I could shut off easily: ie. Stepper Control

3. Moved code around and commented different sections out. I know that it is the bl.init() function that locks everything up either in Setup, Loop, or as a command.

0 Kudos
Message 4 of 6
(3,694 Views)

Are you using some kind of library specifically for this?  Is there a reason you are not using the SPI functions built into LIFA?

0 Kudos
Message 5 of 6
(3,694 Views)

I am. I have 80x RGB LEDs from Bliptronics and I'm using the library that they provided. The reason that I am not using LVIFA SPI is because (my understanding of it) is that it is a software SPI library. Using the Hardware driven SPI (Arduino IDE calls it 'Fast SPI') allows these lights to work better. There is visible flickering in the lights with normal SPI. I believe that it is because the LED driver requires a continuous clock output to keep going cleanly.

0 Kudos
Message 6 of 6
(3,694 Views)