Actually I need to make LEDS glow using the data provided by SPI.
For that purpose,
I have used SPI Master,SPI Slave and LEDs,LM32 processor in lattice MICO.
I have written below code as well..
#include "DDStructs.h"
#include "stdio.h"
#include "MicoUtils.h"
#include "LookupServices.h"
#include "MicoSPIService.h"
#include "system_conf.h"
#include "MicoGPIO.h"
const char *LED_GPIO_INSTANCE = "LEDS";
const char *SPI_SLAVE="SPI_SLAVE";
const char *SPI_MASTER="SPI_MASTER";
volatile MicoGPIO_t *pGPIO;
int main(void)
{
int slave_address= 0x80000200;
int slave_txdata= 0xC0;
int *pdata;
//int master_txdata= 0xC;//
MicoSPICtx_t *pmaster;
MicoSPICtx_t *pslave;
MicoGPIOCtx_t *leds;
//initialisation of the SPI modules//
MicoSPIInit(pmaster);
MicoSPIInit(pslave);
leds = (MicoGPIOCtx_t*)MicoGetDevice("LEDS");
pmaster=(MicoSPICtx_t*)MicoGetDevice("SPI_MASTER");/* Fetch SPI Master named "SPI_MASTER" */
pslave=(MicoSPICtx_t*) MicoGetDevice("SPI_SLAVE");/*Fetch SPI SLAVE named "SPI_SLAVE" */
/*Check for LED */
if (leds == 0) {
printf("failed to find GPIO instance named %s\n",LED_GPIO_INSTANCE);
return(0);
}
/*Check for SPI_MASTER */
if(pmaster==0){
printf("failed to find the SPI_MASTER instance named %s \n",SPI_MASTER);
return (0);
}
/*Check for SPI_SLAVE */
if(pslave==0){
printf("failed to find the SPI_SLAVE instance named %s \n",SPI_SLAVE);
return (0);
}
//{
MicoSPITxData(pslave,slave_txdata,1); /* Write Slave Data: Block till loaded */
MicoSPISetSlaveEnable(pmaster,slave_address); //
MicoSPIGetSlaveEnable(pmaster,&slave_address);/* Check slave enable status. */
if(slave_address != 0x80000200){
printf("failed to select internal slave! fatal error\n");
while(1);
}
//}
pGPIO = (volatile MicoGPIO_t *)(leds->base);
/* write 0x80 to programmable I/O pins 7 through 0 via the data
register. */
pGPIO->data = MicoSPIRxData(pslave,&pdata,1); ;
Main issue is how are SPI master and SLave connected?
Instance generated by the latticeMICO in verilog is
spi_proj spi_proj_u (
.clk_i(clk_i),
.reset_n(reset_n)
, .SPI_SLAVEMISO_SLAVE(SPI_SLAVEMISO_SLAVE) //
, .SPI_SLAVEMOSI_SLAVE(SPI_SLAVEMOSI_SLAVE) //
, .SPI_SLAVESS_N_SLAVE(SPI_SLAVESS_N_SLAVE) //
, .SPI_SLAVESCLK_SLAVE(SPI_SLAVESCLK_SLAVE) //
, .SPI_MASTERMISO_MASTER(SPI_MASTERMISO_MASTER) //
, .SPI_MASTERMOSI_MASTER(SPI_MASTERMOSI_MASTER) //
, .SPI_MASTERSS_N_MASTER(SPI_MASTERSS_N_MASTER) // [1-1:0]
, .SPI_MASTERSCLK_MASTER(SPI_MASTERSCLK_MASTER) //
, .LEDSPIO_OUT(LEDSPIO_OUT) // [8-1:0]
);
Here masters are connected to masters and slaves to slaves...
but the data flow should be from master to slave right....
And where shud I connect the LEDs to.?
I am totally confused..Please help me out
I have to use controller because I am using LatticeMICO as there is no hard SPI block/core in the kit provided.I have to use soft IP component itself.