AnsweredAssumed Answered

SPI looping on BF592

Question asked by dude on Mar 6, 2013
Latest reply on Mar 20, 2013 by Prashant

Hi all!!

 

Am new to Blackfin and am learning SPI coding on BF592. I tried running the program below but it seems to have a glitch that am unable to find. Hoping for someone to help me out..

 

#include <stdio.h>

#include "ccblkfn.h"

#include "sys/exception.h"

#include <blackfin.h>

#include "cdefBF592-A.h"

#include "bfrom.h"

#define SCLK_freq 75000000

#define TIMODE(val) val

#define SPS 10

int i=0;

unsigned short int DData[10];

unsigned short int TData[10]={1,2,3,4,5,6,7,8,9,10};

EX_INTERRUPT_HANDLER(SPI1_DMA6_ISR);

int main( void )

{

          //PLL Config

          ADI_SYSCTRL_VALUES sys_cntrl_struct;

//ClkIn = 25MHz

    sys_cntrl_struct.uwPllCtl = 0x1800;//VCO = 12*ClkIn = 300MHz

    sys_cntrl_struct.uwPllDiv = 0x0004;//SClk = VCO/4 = 75MHz

    sys_cntrl_struct.uwVrCtl = 0x70D0;

bfrom_SysControl( SYSCTRL_WRITE | SYSCTRL_PLLCTL | SYSCTRL_VRCTL | SYSCTRL_INTVOLTAGE, &sys_cntrl_struct, NULL);

    ssync();

   *pPLL_DIV = sys_cntrl_struct.uwPllDiv; //considering Anomaly No-05000440

    ssync();

      //GPIO configuration

          *pPORTG_MUX = 0x0002;//Use pins for SPI1 (SSel1, SPI1CLK, SPI1MOSI, SPI1MISO)

          *pPORTG_FER = PG1 | PG8 | PG9 | PG10;//Enable pins

      //SPI1 configuration

          //Each 16-bit Sample takes 17 SPICLK cycles

          //Enable SSel1

          //Master, 16-bit, active high SCK, hardware SSel

          //MSB first, Enable MISO, SPI1 mode = Receive through DMA

          *pSPI1_BAUD = SCLK_freq/(2 * 17 * SPS);

          *pSPI1_FLG |= FLS1;

          *pSPI1_CTL = MSTR | EMISO | SIZE | TIMODE(2);

//SPI1 (DMA6) Interrupt configuration

          *pSIC_IMASK0 |= 0x00004000;

          register_handler(ik_ivg10, SPI1_DMA6_ISR);

          //register_handler(ik_ivg10, SPI0_DMA5_ISR);

          //DMA6 configuration

          //DMA Start Address = Receive buffer (DData)

          //No of samples = length of DData

          //Size of a sample = size of one DData word

          //DMA interrupt after DMA transfer done enabled

          //Write to memory, DMA word size is 16 bit

          //Enable DMA

          *pDMA6_START_ADDR = DData;

          *pDMA6_X_COUNT = sizeof(DData) / sizeof(DData[0]);

          *pDMA6_X_MODIFY = sizeof(DData[0]);

          *pDMA6_CONFIG = DI_EN | SYNC | WNR | WDSIZE_16 | DMAEN;

//Enable SPI0 as a slave

          *pSPI1_CTL |= SPE;

              //GPIO configuration

          *pPORTG_MUX = 0x0001;//Use pins for SPI0 (SSel1, SPI0CLK, SPI0MOSI, SPI0MISO)

    *pPORTF_MUX = 0x0000;

          *pPORTG_FER = PG0;//Enable pins

    *pPORTF_FER = PF13|PF14|PF15;

//SPI0 configuration

          //MSB first, Enable MISO, SPI0 mode = Receive through DMA

          *pSPI0_CTL =  EMISO | SIZE | TIMODE(2);

//DMA5 configuration

          //DMA Start Address = Receive buffer (TData)

          //No of samples = length of TData

          //Size of a sample = size of one TData word

          //DMA interrupt after DMA transfer done enabled

          //Write to memory, DMA word size is 16 bit

          //Enable DMA

          *pDMA5_START_ADDR = TData;

          *pDMA5_X_COUNT = sizeof(TData) / sizeof(TData[0]);

          *pDMA5_X_MODIFY = sizeof(TData[0]);

          *pDMA5_CONFIG = DI_EN | SYNC|WDSIZE_16 | DMAEN;

//Enable SPI0

          *pSPI0_CTL |= SPE;

while(1)

          { }

          return 0;

}

EX_INTERRUPT_HANDLER(SPI1_DMA6_ISR)

{

printf("in interrupt fn");

          *pDMA6_IRQ_STATUS = DMA_DONE;

while((*pSPI1_STAT & TXS));

          while(!(*pSPI1_STAT & SPIF));

*pSPI1_CTL &= ~SPE;

          for(i=0;i<10;i++)

          {

          printf("in receiving end");

          printf("%d \t",DData[i]); }

                              ssync();

}

Thanks in advance!!

Outcomes