Exemplo n.º 1
0
int main( void )
{
    uint8_t d = 0x34,rxbuf = 0X23;
    mInit();
    // I2C_config();
    SPI_config();
    debug_setup();
    ADC_A_config();
    GPIO_InitTypeDef  GPIO_InitStructure;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //M4 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; //M3 DIRECTION
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
    TIMA_config(100, 20,10); // timer1 channel 1 PA8
    TIMB_config(100, 20,10); // timer2 channel 3 PA9
    TIMC_config(100, 20,10); // timer15 channel 1 PB14
    TIMD_config(100, 20,10); // timer2 channel 2 PA1 // first 2 numbers
    //                          // in this function are not doing anything   
    while(1)
    {
        GPIO_ResetBits(GPIOA, GPIO_Pin_0);
        GPIO_ResetBits(GPIOB, GPIO_Pin_15);
        // debug_write_ch(0XAB);
        mBlueTOGGLE;
        mGreenTOGGLE;
        mRedTOGGLE;
        mWaitms(300);
        GPIO_SetBits(GPIOA, GPIO_Pin_0);
        GPIO_SetBits(GPIOB, GPIO_Pin_15);
            /* Test EOC flag */
        while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
    
        /* Get ADC1 converted data */
        ADC1ConvertedValue =ADC_GetConversionValue(ADC1);
        debug_write_u16(ADC1ConvertedValue,10);
        debug_write_line("  ");

        // mWaitms(300);
        // I2C_write_1byte(SLAVE_ADDR2,254,22);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR1,254);
        // debug_write_ch(rxbuf);
        // rxbuf = I2C_read_1byte(SLAVE_ADDR2,254);
        // debug_write_ch(rxbuf);
    // TIM_SetCompare2 ( TIM2,1);
    // mWaitms(300);
    // TIM_SetCompare2 ( TIM2,0);
    // mWaitms(1000);
        // SPI_SendData8(SPI1, d);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);
        // while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
        // rxbuf =  SPI_ReceiveData8(SPI1);
    }

}
Exemplo n.º 2
0
Int16 spi_eeprom_init(CSL_SpiHandle spiHandle)
{
	volatile Int16 looper;
	Int16 		   result;
	SPI_Config	   hwConfig;

	CSL_SYSCTRL_REGS->PSRCR = (Uint16)0x04;
	CSL_SYSCTRL_REGS->PRCR  = (Uint16)0x00FF;

	CSL_SPI_REGS->SPICDR   = (Uint16)0x00;
	CSL_SPI_REGS->SPICCR   = (Uint16)0x00;

	CSL_SPI_REGS->SPIDCR1  = (Uint16)0x00;
	CSL_SPI_REGS->SPIDCR2  = (Uint16)0x00;
	CSL_SPI_REGS->SPICMD1  = (Uint16)0x00;
	CSL_SPI_REGS->SPICMD2  = (Uint16)0x00;
	CSL_SPI_REGS->SPISTAT1 = (Uint16)0x00;
	CSL_SPI_REGS->SPISTAT2 = (Uint16)0x00;
	CSL_SPI_REGS->SPIDR1   = (Uint16)0x00;
	CSL_SPI_REGS->SPIDR2   = (Uint16)0x00;

	for(looper = 0; looper < 100; looper++) {;}

	/* Enable SPI with PPMODE as MODE5 */
//	CSL_SYSCTRL_REGS->EBSR = (Uint16)0x5000;
#if (defined (C5535_EZDSP))
    result = SYS_setEBSR(CSL_EBSR_FIELD_PPMODE,
                         CSL_EBSR_PPMODE_1);
#else
    result = SYS_setEBSR(CSL_EBSR_FIELD_PPMODE,
                         CSL_EBSR_PPMODE_3);
#endif
	if (CSL_SOK != result)
    {
        printf("SYS_setEBSR failed\n");
        return (result);
    }

	CSL_SPI_REGS->SPICCR = (Uint16)(1<<15);

	/** Set the hardware configuration 							*/
	hwConfig.spiClkDiv	= SPI_CLK_DIV;
	hwConfig.wLen		= SPI_WORD_LENGTH_8;
	hwConfig.frLen		= SPI_FRAME_LENGTH;
	hwConfig.wcEnable	= SPI_WORD_IRQ_ENABLE;
	hwConfig.fcEnable	= SPI_FRAME_IRQ_DISABLE;
	hwConfig.csNum		= SPI_CS_NUM_0;
	hwConfig.dataDelay	= SPI_DATA_DLY_0;
	hwConfig.csPol		= SPI_CSP_ACTIVE_LOW;
	hwConfig.clkPol		= SPI_CLKP_LOW_AT_IDLE;
	hwConfig.clkPh		= SPI_CLK_PH_FALL_EDGE;

	result = SPI_config(spiHandle, &hwConfig);

	if(CSL_SOK != result)
	{
		printf ("SPI Instance Configuration Failed\n");
		return (result);
	}
	else
	{
		printf ("SPI Instance Configured successfully\n");
	}

	CSL_SPI_REGS->SPICCR = (Uint16)(1<<15);
	/* Wait for SPI ready */
	while((CSL_SPI_REGS->SPISTAT1 & 0x0001) != 0) {};

    /* Clear Block Protection */
    commandBuf[0] = 0x01; // SPI_CMD_WRSR
    commandBuf[1] = 0xC3;

    CSL_SPI_REGS->SPICMD1 = (Uint16)0x0000 | 2 - 1;
    for (looper = 0; looper < 2; looper++)
    {
		CSL_SPI_REGS->SPIDR2 = (Uint16)commandBuf[looper] << 8;
		CSL_SPI_REGS->SPIDR1 = (Uint16)0x0000;
        CSL_SPI_REGS->SPICMD2 = (Uint16)0x0039;  //  8-bit words, read
        while((CSL_SPI_REGS->SPISTAT1 & 0x0002) == 0) {};
        commandBuf[looper] = CSL_SPI_REGS->SPIDR2 & 0xff;
	}

	while((CSL_SPI_REGS->SPISTAT1 & 0x0001) != 0) {};

    return (result);
}