Beispiel #1
0
/**
 * \brief Initialization of the SPI for communication with ADS7843 component.
 */
extern void ADS7843_Initialize( void )
{
    volatile uint32_t uDummy;

    /* Configure pins */
    PIO_Configure(pinsSPI, PIO_LISTSIZE(pinsSPI));

    PIO_Configure(pinBusy, PIO_LISTSIZE(pinBusy));

    SPI_Configure(BOARD_TSC_SPI_BASE,
                  BOARD_TSC_SPI_ID,
                  SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS(BOARD_TSC_NPCS) /* Value of the SPI configuration register. */
    );

    SPI_ConfigureNPCS(BOARD_TSC_SPI_BASE, BOARD_TSC_NPCS,
                      SPI_CSR_NCPHA | SPI_CSR_DLYBS(DELAY_BEFORE_SPCK) |
                      SPI_CSR_DLYBCT(DELAY_BETWEEN_CONS_COM) | SPI_CSR_SCBR(0xC8) );

    SPI_Enable(BOARD_TSC_SPI_BASE);

    for (uDummy=0; uDummy<100000; uDummy++);

    uDummy = REG_SPI_SR;
    uDummy = REG_SPI_RDR;

    SendCommand(CMD_ENABLE_PENIRQ);
}
Beispiel #2
0
   // hardware SPI
   void HAL::spiBegin()
   {
        // Configre SPI pins
        PIO_Configure(
           g_APinDescription[SCK_PIN].pPort,
           g_APinDescription[SCK_PIN].ulPinType,
           g_APinDescription[SCK_PIN].ulPin,
           g_APinDescription[SCK_PIN].ulPinConfiguration);
        PIO_Configure(
           g_APinDescription[MOSI_PIN].pPort,
           g_APinDescription[MOSI_PIN].ulPinType,
           g_APinDescription[MOSI_PIN].ulPin,
           g_APinDescription[MOSI_PIN].ulPinConfiguration);
        PIO_Configure(
           g_APinDescription[MISO_PIN].pPort,
           g_APinDescription[MISO_PIN].ulPinType,
           g_APinDescription[MISO_PIN].ulPin,
           g_APinDescription[MISO_PIN].ulPinConfiguration);

        // set master mode, peripheral select, fault detection
        SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR | 
                     SPI_MR_MODFDIS | SPI_MR_PS);
       SPI_Enable(SPI0);
        PIO_Configure(
           g_APinDescription[SPI_PIN].pPort,
           g_APinDescription[SPI_PIN].ulPinType,
           g_APinDescription[SPI_PIN].ulPin,
           g_APinDescription[SPI_PIN].ulPinConfiguration);
        spiInit(1);
   }
Beispiel #3
0
/**
 * \brief Initialize SPI as slave
 */
static void SpiSlaveInitialize( void )
{
    uint32_t i ;
    printf("-I- Initialize SPI as slave ...\n\r");
    /* Configures a SPI peripheral */
    SPI_Configure(SPI_SLAVE_BASE, ID_SPI, 0);
    SPI_ConfigureNPCS(SPI_SLAVE_BASE, 0 , 0);
    /* Disable the RX and TX PDC transfer requests */
    SPI_PdcDisableTx(SPI_MASTER_BASE);
    SPI_PdcDisableRx(SPI_MASTER_BASE);
    /* Enables a SPI peripheral. */
    SPI_Enable(SPI_SLAVE_BASE);

    /* Reset status */
    spiStatus.totalNumBlocks   = 0;
    spiStatus.totalNumCommands = 0;
    for ( i = 0; i < NB_STATUS_CMD; i++ )
    {
        spiStatus.cmdList[i] = 0 ;
    }

    /* Start waiting command */
    spiState = SLAVE_STATE_IDLE;
    spiCmd = RC_SYN;
    SpiSlaveTransfer(&spiCmd, 4, 0, 0);
}
Beispiel #4
0
/**
 *  \brief Configures spi in spi_mode with respect to state
 */
static void _ConfigureSpi( uint8_t state )
{
    uint32_t mode = SPI_MR_MSTR ;
    uint32_t csr0 ;

    /* spi in slave mode */
    if ( state == STATE_UM_SS )
    {
        mode &= (uint32_t) (~(SPI_MR_MSTR)) ;
    }
    csr0 = SPI_CSR_BITS_8_BIT | SPI_CSR_DLYBS(0xFF) ;

    /* spi clock */
    if ( state == STATE_US_SM )
    {
        csr0 |= ((BOARD_MCK/USART_SPI_CLK) << 8 ) ;
    }
    /* configure SPI mode */
    SPI_Configure( SPI, ID_SPI, mode ) ;

    NVIC_EnableIRQ( SPI_IRQn ) ;
    /* configure SPI csr0*/
    SPI_ConfigureNPCS( SPI, 0, csr0 ) ;

    SPI_Enable( SPI ) ;
}
void ledsInit(void){

    uint8_t i;

    //init SPI
    SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_MR_PCS(0));
    SPI_ConfigureNPCS(SPI0, 0 , SPI_CSR_NCPHA | SPI_CSR_BITS_12_BIT | SPI_CSR_SCBR(3) | SPI_CSR_DLYBS(2) | SPI_CSR_DLYBCT(0)); //30MHz spi speed
    SPI_Enable(SPI0);
    SPI0->SPI_IDR = 0xFFFFFFFF;
    NVIC_EnableIRQ(SPI0_IRQn);

    //init pins: SPI
    gpioSetFun(MISO, GPIO_FUNC_A);
    gpioSetFun(MOSI, GPIO_FUNC_A);
    gpioSetFun(SCLK, GPIO_FUNC_A);

    //init pins: debug LED
    gpioSetFun(DBGLED, GPIO_FUNC_GPIO);
    gpioSetDir(DBGLED, 0);
    gpioSetVal(DBGLED, 0);

    //init pins: latch
    gpioSetFun(XLAT, GPIO_FUNC_GPIO);
    gpioSetDir(XLAT, 0);
    gpioSetVal(XLAT, 0);

    //init pins: blanking
    for(i = 0; i < sizeof(blanks); i++){
        gpioSetFun(blanks[i], GPIO_FUNC_GPIO);
        gpioSetDir(blanks[i], 0);
        gpioSetVal(blanks[i], 1);
    }

    periodicAdd(ledUpdate, 0, 4);
}
/**
 * \brief ILI9488 Hardware Initialization for SPI/SMC LCD.
 */
static void _ILI9488_Spi_HW_Initialize(void)
{
	/* Pin configurations */
	PIO_Configure(&lcd_spi_reset_pin, 1);
	PIO_Configure(&lcd_spi_cds_pin, 1);
	PIO_Configure(lcd_pins, PIO_LISTSIZE(lcd_pins));
	PIO_Configure(&lcd_spi_pwm_pin, 1);

	/* Enable PWM peripheral clock */
	PMC_EnablePeripheral(ID_PWM0);
	PMC_EnablePeripheral(ID_SPI0);
	/* Set clock A and clock B */
	// set for 14.11 KHz for CABC control
	//mode = PWM_CLK_PREB(0x0A) | (PWM_CLK_DIVB(110)) |
	//PWM_CLK_PREA(0x0A) | (PWM_CLK_DIVA(110));
	PWMC_ConfigureClocks(PWM0, 14200, 0,  BOARD_MCK);

	/* Configure PWM channel 1 for LED0  */
	PWMC_DisableChannel(PWM0, CHANNEL_PWM_LCD);

	PWMC_ConfigureChannel(PWM0, CHANNEL_PWM_LCD, PWM_CMR_CPRE_CLKA, 0,
						  PWM_CMR_CPOL);
	PWMC_SetPeriod(PWM0, CHANNEL_PWM_LCD, 16);
	PWMC_SetDutyCycle(PWM0, CHANNEL_PWM_LCD, 8);
	PWMC_EnableChannel(PWM0, CHANNEL_PWM_LCD);

	SPI_Configure(ILI9488_SPI, ID_SPI0, (SPI_MR_MSTR | SPI_MR_MODFDIS
										 | SPI_PCS(SMC_EBI_LCD_CS)));
	SPI_ConfigureNPCS(ILI9488_SPI,
					  SMC_EBI_LCD_CS,
					  SPI_CSR_CPOL | SPI_CSR_BITS_8_BIT | SPI_DLYBS(6, BOARD_MCK)
					  | SPI_DLYBCT(100, BOARD_MCK) | SPI_SCBR(20000000, BOARD_MCK));
	SPI_Enable(ILI9488_SPI);
}
Beispiel #7
0
static void ILI9488_InitInterface(void)
{

    PIO_Configure(ILI9488_Reset, PIO_LISTSIZE(ILI9488_Reset));    
    PIO_Configure(spi_pins, PIO_LISTSIZE(spi_pins));


    PIO_Configure(ILI9488_Pwm, PIO_LISTSIZE(ILI9488_Pwm));
    /* Enable PWM peripheral clock */
    PMC_EnablePeripheral(ID_PWM0);

    /* Set clock A and clock B */
    // set for 14.11 KHz for CABC control
    //    mode = PWM_CLK_PREB(0x0A) | (PWM_CLK_DIVB(110)) | 
    //           PWM_CLK_PREA(0x0A) | (PWM_CLK_DIVA(110));
    PWMC_ConfigureClocks(PWM0, 14200, 0,  BOARD_MCK);

    /* Configure PWM channel 1 for LED0  */
    PWMC_DisableChannel(PWM0, CHANNEL_PWM_LCD);

    PWMC_ConfigureChannel(PWM0, CHANNEL_PWM_LCD, PWM_CMR_CPRE_CLKA,0,PWM_CMR_CPOL);
    PWMC_SetPeriod(PWM0, CHANNEL_PWM_LCD, 16);
    PWMC_SetDutyCycle(PWM0, CHANNEL_PWM_LCD, 8);
    PWMC_EnableChannel(PWM0, CHANNEL_PWM_LCD);

    SPI_Configure(ILI9488, ILI9488_ID, (SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS( ILI9488_cs )));
    SPI_ConfigureNPCS( ILI9488, ILI9488_cs, 
            SPI_CSR_CPOL | SPI_CSR_BITS_9_BIT | 
            SPI_DLYBS(100, BOARD_MCK) | SPI_DLYBCT(100, BOARD_MCK) |
            SPI_SCBR( 35000000, BOARD_MCK) ) ;  

    SPI_Enable(ILI9488);

}
Beispiel #8
0
void SPIClass::init() {
	if (initialized)
		return;
	initCb();
	SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
	SPI_Enable(spi);
	initialized = true;
}
Beispiel #9
0
/**
 * \brief Interrupt handler for the SPI slave.
 */
void SPI_IrqHandler( void )
{
    uint32_t status;
    uint8_t startNew = 0;
    status = SPI_GetStatus( SPI_SLAVE_BASE ) ;

    if ( status & SPI_SR_NSSR )
    {
        if ( status & SPI_SR_RXBUFF )
        {
            /* Disable the RX and TX PDC transfer requests */
            SPI_PdcDisableTx( SPI_SLAVE_BASE ) ;
            SPI_PdcDisableRx( SPI_SLAVE_BASE ) ;
        }

        if ( status & SPI_IDR_ENDRX )
        {
            SPI_DisableIt( SPI_SLAVE_BASE, SPI_IDR_ENDRX ) ;
        }

        switch ( status & (SPI_SR_RXBUFF | SPI_SR_ENDRX) )
        {
            case (SPI_SR_RXBUFF | SPI_SR_ENDRX):
            case (SPI_SR_RXBUFF):
                SpiSlaveCommandProcess() ;
                startNew = 1 ;
            break ;

            /* Maybe command break data transfer, start new */
            case SPI_SR_ENDRX:
            {
                /* Command breaks data transfer */
                SPI_PdcDisableTx( SPI_SLAVE_BASE ) ;
                SPI_PdcDisableRx( SPI_SLAVE_BASE ) ;
                SPI_Configure( SPI_SLAVE_BASE, ID_SPI, 0 ) ;
                SPI_ConfigureNPCS( SPI_SLAVE_BASE, 0 , 0 ) ;
                startNew = 1 ;
            }
            break;

            default:
            break;
        }

        if ( startNew )
        {
            if ( spiCmd != CMD_END )
            {
                spiStatus.cmdList[spiStatus.totalNumCommands] = spiCmd;
                spiStatus.totalNumCommands ++;
            }
            SpiSlaveNewCommand();
        }
    }

}
Beispiel #10
0
void SPIClass::begin() {
	initCb();
	SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
	SPI_Enable(spi);

	// NPCS control is left to the user

	// Default speed set to 4Mhz
	setClockDivider(BOARD_SPI_DEFAULT_SS, 21);
	setDataMode(BOARD_SPI_DEFAULT_SS, SPI_MODE0);
	setBitOrder(BOARD_SPI_DEFAULT_SS, MSBFIRST);
}
Beispiel #11
0
Datei: main.c Projekt: gstroe/Arm
/**
 * \brief Configures spi in slave mode.
 */
static void _ConfigureSpiSlave( void )
{
	/* Configure SPI slave mode */
	SPI_Configure(SPI, ID_SPI, SPI_PCS(0));

	NVIC_ClearPendingIRQ(SPI_IRQn);
	NVIC_SetPriority(SPI_IRQn ,1);
	NVIC_EnableIRQ(SPI_IRQn);
	SPI_DisableIt(SPI, 0xffffffff);

	SPI_ConfigureNPCS(SPI, 0, 0);
}
void HAL::spiBegin()
{
#if MOTHERBOARD == 500 || MOTHERBOARD == 501
  if (spiInitMaded == false)
  {
#endif        // Configre SPI pins
    PIO_Configure(
      g_APinDescription[SCK_PIN].pPort,
      g_APinDescription[SCK_PIN].ulPinType,
      g_APinDescription[SCK_PIN].ulPin,
      g_APinDescription[SCK_PIN].ulPinConfiguration);
    PIO_Configure(
      g_APinDescription[MOSI_PIN].pPort,
      g_APinDescription[MOSI_PIN].ulPinType,
      g_APinDescription[MOSI_PIN].ulPin,
      g_APinDescription[MOSI_PIN].ulPinConfiguration);
    PIO_Configure(
      g_APinDescription[MISO_PIN].pPort,
      g_APinDescription[MISO_PIN].ulPinType,
      g_APinDescription[MISO_PIN].ulPin,
      g_APinDescription[MISO_PIN].ulPinConfiguration);

    // set master mode, peripheral select, fault detection
    SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR |
                  SPI_MR_MODFDIS | SPI_MR_PS);
    SPI_Enable(SPI0);
#if MOTHERBOARD == 500 || MOTHERBOARD == 501
    SET_OUTPUT(DAC0_SYNC);
#if NUM_EXTRUDER > 1
    SET_OUTPUT(DAC1_SYNC);
    WRITE(DAC1_SYNC, HIGH);
#endif
    SET_OUTPUT(SPI_EEPROM1_CS);
    SET_OUTPUT(SPI_EEPROM2_CS);
    SET_OUTPUT(SPI_FLASH_CS);
    WRITE(DAC0_SYNC, HIGH);
    WRITE(SPI_EEPROM1_CS, HIGH );
    WRITE(SPI_EEPROM2_CS, HIGH );
    WRITE(SPI_FLASH_CS, HIGH );
    WRITE(SDSS , HIGH );
#endif// MOTHERBOARD == 500 || MOTHERBOARD == 501
    PIO_Configure(
      g_APinDescription[SPI_PIN].pPort,
      g_APinDescription[SPI_PIN].ulPinType,
      g_APinDescription[SPI_PIN].ulPin,
      g_APinDescription[SPI_PIN].ulPinConfiguration);
    spiInit(1);
#if (MOTHERBOARD==500) || (MOTHERBOARD==501)
    spiInitMaded = true;
  }
#endif
}
Beispiel #13
0
void InitPeriph(void)
{
    CRC_Configure();
    TIM_Configure();
    GPIO_Configure();
    USART_Configure();

    ADC_Configure();
    RTC_Configure();
    RTC_Time_Configure(0, 0, 0);
    RTC_Alarm_Configure(0xFF, 20, 0); //Alarm each 20 min (Check humidity)

    dxdev_out(USART_SendChar);
    SPI_Configure();
}
Beispiel #14
0
/**
 * \brief Initialize SPI as master
 */
static void SpiMasterInitialize( void )
{
    printf( "-I- Configure SPI as master\n\r" ) ;

    /* Master mode */
    SPI_Configure( SPI_MASTER_BASE, ID_SPI, SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS( 0 ) ) ;
    SPI_ConfigureNPCS( SPI_MASTER_BASE, 0, SPI_DLYBCT( 100000, BOARD_MCK ) | SPI_DLYBS(100000, BOARD_MCK) | SPI_SCBR( spiClock, BOARD_MCK) ) ;

    /* Disable the RX and TX PDC transfer requests */
    SPI_PdcDisableTx( SPI_MASTER_BASE ) ;
    SPI_PdcDisableRx( SPI_MASTER_BASE ) ;

    /* Enables a SPI peripheral. */
    SPI_Enable( SPI_MASTER_BASE ) ;
}
Beispiel #15
0
Datei: main.c Projekt: gstroe/Arm
/**
 * \brief Configures spi in master mode.
 */
static void _ConfigureSpiMaster(void)
{
	/* Configure SPI master mode */
	SPI_Configure(SPI, ID_SPI, (SPI_MR_MSTR | SPI_MR_MODFDIS | SPI_PCS(1)));

	NVIC_ClearPendingIRQ(SPI_IRQn);
	NVIC_SetPriority(SPI_IRQn ,1);
	NVIC_EnableIRQ(SPI_IRQn);
	SPI_DisableIt(SPI, 0xffffffff);

	SPI_ConfigureNPCS(SPI, 1,
					  SPI_DLYBCT( 100, BOARD_MCK ) |
					  SPI_DLYBS(100, BOARD_MCK) |
					  SPI_SCBR( spiClock, BOARD_MCK) |
					  SPI_CSR_BITS_8_BIT);
}
Beispiel #16
0
void SPIClass::begin(uint8_t _pin) {
	initCb();
	SPI_Configure(spi, id, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
	SPI_Enable(spi);

	uint32_t spiPin = BOARD_PIN_TO_SPI_PIN(_pin);
	PIO_Configure(
		g_APinDescription[spiPin].pPort,
		g_APinDescription[spiPin].ulPinType,
		g_APinDescription[spiPin].ulPin,
		g_APinDescription[spiPin].ulPinConfiguration);

	// Default speed set to 4Mhz
	setClockDivider(_pin, 21);
	setDataMode(_pin, SPI_MODE0);
	setBitOrder(_pin, MSBFIRST);
}
Beispiel #17
0
void hwspi0_init_default(void){
	pmc_enable_periph_clk(ID_SPI0);
	pmc_enable_periph_clk(ID_PIOA);
	
	PIO_Configure(PIOA, PIO_PERIPH_A, PIO_MOSI, PIO_DEFAULT); 
	PIO_Configure(PIOA, PIO_PERIPH_A, PIO_MISO, PIO_DEFAULT); 
	PIO_Configure(PIOA, PIO_PERIPH_A, PIO_SCK, 	PIO_DEFAULT); 
	
	SPI_Configure(SPI0, ID_SPI0, SPI_MR_MSTR | SPI_MR_PS | SPI_MR_MODFDIS);
	SPI_Enable(SPI0);
	
	SPI_ConfigureNPCS(SPI0, 0, SPI_CSR_CSAAT | SPI_MODE0 | SPI_CSR_SCBR(SPI_CLOCK_DIV16) | SPI_CSR_DLYBCT(1));
	SPI_ConfigureNPCS(SPI0, 1, SPI_CSR_CSAAT | SPI_MODE0 | SPI_CSR_SCBR(SPI_CLOCK_DIV16) | SPI_CSR_DLYBCT(1));
	SPI_ConfigureNPCS(SPI0, 2, SPI_CSR_CSAAT | SPI_MODE0 | SPI_CSR_SCBR(SPI_CLOCK_DIV16) | SPI_CSR_DLYBCT(1));
	SPI_ConfigureNPCS(SPI0, 3, SPI_CSR_CSAAT | SPI_MODE0 | SPI_CSR_SCBR(SPI_CLOCK_DIV16) | SPI_CSR_DLYBCT(1));
	//SPI_ConfigureNPCS(SPI0, 0, SPI_BITS_8 | SCBR);
}
Beispiel #18
0
void spi_stack_master_init(void) {
	Pin spi_master_pins[] = {PINS_SPI};
	PIO_Configure(spi_master_pins, PIO_LISTSIZE(spi_master_pins));
#ifndef CONSOLE_USART_USE_UART1
	if(master_get_hardware_version() > 10) {
		Pin spi_select_7_20 = PIN_SPI_SELECT_MASTER_7_20;
		memcpy(&spi_select_master[7], &spi_select_7_20, sizeof(Pin));
	} else {
		Pin spi_select_7_10 = PIN_SPI_SELECT_MASTER_7_10;
		memcpy(&spi_select_master[7], &spi_select_7_10, sizeof(Pin));
	}

	PIO_Configure(spi_select_master, 8);
#else
	PIO_Configure(spi_select_master, 7);
#endif

    // Master mode configuration
    SPI_Configure(SPI,
                  ID_SPI,
                  // Master mode
                  SPI_MR_MSTR |
                  // Mode fault detection disabled
                  SPI_MR_MODFDIS |
                  // Wait until receive register empty before read
                  SPI_MR_WDRBT |
                  // Chip select number
                  SPI_PCS(0) |
                  // Delay between chip selects
                  SPI_DLYBCS(SPI_DELAY_BETWEEN_CHIP_SELECT, BOARD_MCK));

    // Configure slave select
    SPI_ConfigureNPCS(SPI,
                      // slave select num
                      0,
                      // Delay between consecutive transfers
                      SPI_DLYBCT(SPI_DELAY_BETWEEN_TRANSFER, BOARD_MCK) |
                      // Delay before first SPCK
                      SPI_DLYBS(SPI_DELAY_BEFORE_FIRST_SPI_CLOCK, BOARD_MCK) |
                      // SPI baud rate
                      SPI_SCBR(SPI_CLOCK, BOARD_MCK));

    // Enable SPI peripheral.
    SPI_Enable(SPI);
}
/**
 * \brief Initializes the Spid structure and the corresponding SPI & DMA hardware.
 * select value.
 * The driver will uses DMA channel 0 for RX and DMA channel 1 for TX.
 * The DMA channels are freed automatically when no SPI command processing.
 *
 * \param pSpid  Pointer to a Spid instance.
 * \param pSpiHw Associated SPI peripheral.
 * \param spiId  SPI peripheral identifier.
 * \param pDmad  Pointer to a Dmad instance. 
 */
uint32_t SPID_Configure( Spid *pSpid ,
                         Spi *pSpiHw , 
                         uint8_t spiId,
                         uint8_t SpiMode,
                         sXdmad *pXdmad )
{
    /* Initialize the SPI structure */
    pSpid->pSpiHw = pSpiHw;
    pSpid->spiId  = spiId;
    pSpid->semaphore = 1;
    pSpid->pCurrentCommand = 0;
    pSpid->pXdmad = pXdmad;

    /* Enable the SPI Peripheral ,Execute a software reset of the SPI, Configure SPI in Master Mode*/
    SPI_Configure ( pSpiHw, pSpid->spiId, SpiMode );
    
    return 0;
}
Beispiel #20
0
// Initialises the SPI controller on the at91.
void Init_SPI(void)
{
    SPI_Configure(AT91C_BASE_SPI0,
        AT91C_ID_SPI0,
        AT91C_SPI_MSTR |
        AT91C_SPI_PS_FIXED |
        AT91C_SPI_MODFDIS |
        SPI_PCS(0)
    ); 
    
    //Configure SPI Chip Select Register.
    SPI_ConfigureNPCS(AT91C_BASE_SPI0,
        0,                  // NPCS0
        AT91C_SPI_NCPHA |   // Mode 0 (CPOL=0,CPHA=0)
        (128 << 8) |        // SCBR: SPCK=MCK/SCBR //8 or 64
        (0 << 16) |         // DLYBS: Delay from NPCS to SPCK in MCK cycles
        (0 << 24) |         // DLYBCT: Delay between consec xfers
        AT91C_SPI_BITS_8    // 8-data bits
    ); 

    SPI_Enable(AT91C_BASE_SPI0);
}
Beispiel #21
0
void spi_stack_slave_init(void) {
	PIO_Configure(spi_slave_pins, PIO_LISTSIZE(spi_slave_pins));

    // Configure SPI interrupts for Slave
    NVIC_DisableIRQ(SPI_IRQn);
    NVIC_ClearPendingIRQ(SPI_IRQn);
    NVIC_SetPriority(SPI_IRQn, PRIORITY_STACK_SLAVE_SPI);
    NVIC_EnableIRQ(SPI_IRQn);

    // Configure SPI peripheral
    SPI_Configure(SPI, ID_SPI, 0);
    SPI_ConfigureNPCS(SPI, 0 , 0);

    // Disable RX and TX DMA transfer requests
    SPI_PdcDisableTx(SPI);
    SPI_PdcDisableRx(SPI);

    // Enable SPI peripheral
    SPI_Enable(SPI);

    // Call interrupt on data in rx buffer
    SPI_EnableIt(SPI, SPI_IER_RDRF);
}
void spi_stack_master_init(void) {
	// Set starting sequence number to something that slave does not expect
	// (default for slave is 0)
	//spi_stack_master_seq = 1;

	for(uint8_t i = 0; i < SPI_ADDRESS_MAX; i++) {
		slave_status[i] = SLAVE_STATUS_ABSENT;
	}

	Pin spi_master_pins[] = {PINS_SPI};
	PIO_Configure(spi_master_pins, PIO_LISTSIZE(spi_master_pins));
#ifndef CONSOLE_USART_USE_UART1
	if(master_get_hardware_version() > 10) {
		Pin spi_select_7_20 = PIN_SPI_SELECT_MASTER_7_20;
		memcpy(&spi_select_master[7], &spi_select_7_20, sizeof(Pin));
	} else {
		Pin spi_select_7_10 = PIN_SPI_SELECT_MASTER_7_10;
		memcpy(&spi_select_master[7], &spi_select_7_10, sizeof(Pin));
	}

	PIO_Configure(spi_select_master, 8);
#else
	PIO_Configure(spi_select_master, 7);
#endif

    // Configure SPI interrupts for Master
    NVIC_DisableIRQ(SPI_IRQn);
    NVIC_ClearPendingIRQ(SPI_IRQn);
    NVIC_SetPriority(SPI_IRQn, PRIORITY_STACK_MASTER_SPI);
    NVIC_EnableIRQ(SPI_IRQn);

    // SPI reset
    SPI->SPI_CR = SPI_CR_SWRST;

    // Master mode configuration
    SPI_Configure(SPI,
                  ID_SPI,
                  // Master mode
                  SPI_MR_MSTR |
                  // Mode fault detection disabled
                  SPI_MR_MODFDIS |
                  // Wait until receive register empty before read
                  SPI_MR_WDRBT |
                  // Chip select number
                  SPI_PCS(0) |
                  // Delay between chip selects
                  SPI_DLYBCS(SPI_DELAY_BETWEEN_CHIP_SELECT, BOARD_MCK));

    // Configure slave select
    SPI_ConfigureNPCS(SPI,
                      // slave select num
                      0,
                      // Delay between consecutive transfers
                      SPI_DLYBCT(SPI_DELAY_BETWEEN_TRANSFER, BOARD_MCK) |
                      // Delay before first SPCK
                      SPI_DLYBS(SPI_DELAY_BEFORE_FIRST_SPI_CLOCK, BOARD_MCK) |
                      // SPI baud rate
                      SPI_SCBR(SPI_CLOCK, BOARD_MCK));

    // Disable RX and TX DMA transfer requests
    spi_stack_master_disable_dma();

    // Enable SPI peripheral.
    SPI_Enable(SPI);

	spi_stack_master_reset_recv_dma_buffer();
	spi_stack_master_reset_send_dma_buffer();

    // Call interrupt on end of slave select
    SPI_EnableIt(SPI, SPI_IER_ENDRX | SPI_IER_ENDTX);
}