コード例 #1
0
ファイル: spi_drv.c プロジェクト: AlexGora/cox
//*****************************************************************************
//
//! \brief Init Spi communction port and wifi handshake pin.
//
//! WiFi shield IO refence volatge == 3.3V
//! Pin map is below:
//! HAND_PIN  --> PA3
//! SPI1_NSS  --> PA4
//! SPI1_SCK  --> PA5
//! SPI1_MISO --> PA6
//! SPI1_MOSI --> PA7
//!
//! \param none.
//!
//! \return None
//
//*****************************************************************************
void SpiDrv_Init(void)
{
    
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    xGPIOSPinTypeGPIOInput(PA3);
    xGPIOSPinTypeGPIOOutput(PA4);

    xSPinTypeSPI(SPI1CLK(3),  PA5);
    xSPinTypeSPI(SPI1MOSI(3), PA7);
    xSPinTypeSPI(SPI1MISO(1), PA6);

    //
    // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(xSPI1_BASE, 4000000, xSPI_MOTO_FORMAT_MODE_0 |
                                                xSPI_MODE_MASTER |
                                                xSPI_MSB_FIRST |
                                                xSPI_DATA_WIDTH8);
    xSPISSSet(xSPI1_BASE, xSPI_SS_SOFTWARE, xSPI_SS0);

    xSPIEnable(xSPI1_BASE);
}
コード例 #2
0
ファイル: spitest01.c プロジェクト: 0xc0170/cox
//*****************************************************************************
//
//! \brief xspi 004 test of SPI0 initialization.
//!
//! \return None.
//
//*****************************************************************************
static void SPI0MasterInit(void)
{
    //
    // Configure Some GPIO pins as SPI Mode
    //
    xSPinTypeSPI(SPI0CLK, PB13);
	xSPinTypeSPI(SPI0MOSI, PB15);
	xSPinTypeSPI(SPI0MISO, PB14);
	xSPinTypeSPI(SPI0CS, PA7);

    //
    // Master Mode polarity 0,Rx latched at rising edge Tx changed at rising edge
    // 200000Hz 8Bits Data windth  SPI MSB First
    //
    xSPIConfigSet(SPI0_BASE, 10000, SPI_FORMAT_MODE_5 | SPI_DATA_WIDTH16 | 
                                               SPI_MSB_FIRST | SPI_MODE_MASTER);
    //
    // Software Control Transfer Select SS0
    //
    xSPISSSet(SPI0_BASE, xSPI_SS_SOFTWARE, 0);

//	SPISSClear(SPI0_BASE);
    
//    xIntEnable(INT_SPI0);

	xSPIIntCallbackInit(SPI0_BASE, SPI0Callback);
    xSPIEnable(SPI0_BASE);
//    xIntPrioritySet(INT_SPI0, 1);
//	xSPIIntEnable(SPI0_BASE, xSPI_INT_EOT);
//	SPIFIFOLevelSet(SPI0_BASE, SPI_FSR_RX, 5);
	
}
コード例 #3
0
ファイル: SPI.cpp プロジェクト: Azz1/RPI_EPI
//Initializes the SPI bus by setting SCK, MOSI, and SS to outputs, pulling SCK and MOSI low, and SS high.
void SPIClass::begin(int spiClock){
    // Enable Peripheral SPIx
    xSysCtlPeripheralEnable2(spiPort);
    xSysCtlPeripheralEnable2(xGPIOSPinToPort(sD13));

    // Configure Some GPIO pins as SPIx Mode
    sPinTypeSPI(spiPort);
    ulDataWidth = xSPI_DATA_WIDTH8;
    ulDataFormat = SPI_MODE0;
    ulDataMode = MSBFIRST;
    xSPIConfigSet(spiPort, spiClock, xSPI_MOTO_FORMAT_MODE_0 | xSPI_DATA_WIDTH8 | xSPI_MSB_FIRST | xSPI_MODE_MASTER);
    xSPISSSet(spiPort, xSPI_SS_HARDWARE, xSPI_SS0);
    xSPIEnable(spiPort);
}
コード例 #4
0
ファイル: main.c プロジェクト: irinakim12/W5500_IPRAW
//////////////////////////////////////////////////////////////////////////////
// Platform (STM32F103X) initialization for peripherals as GPIO, SPI, UARTs //
//////////////////////////////////////////////////////////////////////////////
void platform_init(void)
{
    xSysCtlClockSet(72000000,  xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ);

    xSysCtlDelay((xSysCtlClockGet()/1000)*50); // wait 50ms


    /**************************/
    /* GPIO_A For SPI CS PIN  */// It must be first to enable GPIO peripheral than other peripheral. (Otherwise, UART do not run in STM32F103X)
    /**************************/
    xSysCtlPeripheralEnable( xSYSCTL_PERIPH_GPIOA );
    xGPIODirModeSet(xGPIO_PORTA_BASE, xGPIO_PIN_4, xGPIO_DIR_MODE_OUT);


    /************/
    /* For UART */
    /************/
    xSysCtlPeripheralReset(xSYSCTL_PERIPH_UART1);
    xSysCtlPeripheralEnable(xSYSCTL_PERIPH_UART1);
    xSPinTypeUART(UART1TX,PA9);
    xSPinTypeUART(UART1RX,PA10);
    xUARTConfigSet(xUART1_BASE, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
    xUARTEnable(xUART1_BASE, (UART_BLOCK_UART | UART_BLOCK_TX | UART_BLOCK_RX));


    /***********/
    /* For SPI */
    /***********/
    xSysCtlPeripheralReset(WIZCHIP_SPI_PERIPH);
    xSysCtlPeripheralEnable(WIZCHIP_SPI_PERIPH);
    xSPinTypeSPI(WIZCHIP_SPI_CLK, WIZCHIP_SPI_CLK_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_5, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MOSI,WIZCHIP_SPI_MOSI_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_7, GPIO_TYPE_AFOUT_STD, GPIO_OUT_SPEED_50M);
    xSPinTypeSPI(WIZCHIP_SPI_MISO,WIZCHIP_SPI_MISO_PIN);  // xGPIODirModeSet(xGPIO_PORTA, xGPIO_PIN_6, GPIO_TYPE_IN_FLOATING, GPIO_IN_SPEED_FIXED);
    xSPIConfigSet(WIZCHIP_SPI_BASE, xSysCtlClockGet()/2, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8);

    xSPISSSet(WIZCHIP_SPI_BASE, SPI_SS_SOFTWARE, xSPI_SS_NONE);
    xSPIEnable(WIZCHIP_SPI_BASE);

    printf("HCLK = %dMHz\r\n", (unsigned int)(xSysCtlClockGet()/1000000));
}
コード例 #5
0
ファイル: spitest03.c プロジェクト: 0xc0170/cox
static void xspi004_MasterIntFunction(void)
{
    unsigned long i, ulTemp=0;
    
    //
    // Configure Some GPIO pins as SPI Mode
    //    
    xSPinTypeSPI(SPI0CLK,  PC5);
    xSPinTypeSPI(SPI0CS,   PC4);
    xSPinTypeSPI(SPI0MISO, PC7);
    xSPinTypeSPI(SPI0MOSI, PC6);   
   
    //xHWREGB(xSPI0_BASE + SPI_C1) = 0x54; 
    //xHWREGB(xSPI0_BASE + SPI_C2) = 0x80; 
    //xHWREGB(xSPI0_BASE + SPI_BR) = 0x00; 
    //xHWREGB(xSPI0_BASE + SPI_M) = 0x04;

    //
    // Master Mode polarity 0,Rx latched at rising edge Tx changed at rising edge
    // 2000000Hz 8Bits Data windth SPI MSB First
    //
    ulTemp = xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST;
    
    xSPIConfigSet(xSPI0_BASE, 20000, ulTemp);
    
    xSPIEnable(xSPI0_BASE);

    xIntEnable(INT_SPI0);   
    xIntPrioritySet(INT_SPI0, 1); 
    xSPIIntCallbackInit(xSPI0_BASE, SPI0Callback);
    xSPIIntEnable(xSPI0_BASE, SPI_SPTEF | SPI_SPRF);      
 
    while(!ulFlag);
        
    for(i = 0; i < 8; i++)
    {
        TestAssert((ulSourceData[i] == ulDestData[i]), "xspi API error!");
        ulSourceData[i] = 0;
    }
}
コード例 #6
0
ファイル: hd44780.c プロジェクト: AlexGora/cox
//*****************************************************************************
//
//! \brief Init the HD44780 LCD Device.
//!
//! \param None.
//!
//! This function is used to Init the HD44780 Device. It must be call before 
//! any other LCD function use.
//!
//! It Open the pins's GPIO peripheral port, and config the pins type to GPIO 
//! output. Then config the LCD into the default state, clear the LCD and 
//! Open the display. Default A Blink cursor is set on. The LCD cursor move 
//! direction is config as increment default.
//!
//! The HD44780 Initial state can be determined by the \ref HD44780_Config.
//! - Pins that used is determined by \ref HD44780_Config_Pins.
//! - The inteface data length is determined by \ref HD44780_INTERFACE_DATA_LEN.
//! - The LCD display line is determined by \ref HD44780_DISPLAY_LINE.
//! - The LCD character font is determined by \ref HD44780_CHARACTER_FONT.
//! .
//! 
//! \return None.
//
//*****************************************************************************
void 
HD44780Init(void)
{
	ucDisplayFunction = (HD44780_INTERFACE_DATA_LEN |
                         HD44780_FUNCTION_SET_N_2 |
                         HD44780_CHARACTER_FONT);
	ucRsPin = 1;
	ucRwPin = 255;
	ucEnablePin = 2;
	ucDataPin[0] = 6;
	ucDataPin[1] = 5;
	ucDataPin[2] = 4;
	ucDataPin[3] = 3;
	_SPIbuff = 0;

    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CS));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(HD44780_PIN_MOSI));
     

#if HD44780_SPI_MODE == SPIMODE_HARDWARE
    //
    // Enable Peripheral SPI1
    //
    xSysCtlPeripheralEnable2(HD44780_SPI);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);

    //
    // Configure Some GPIO pins as SPI Mode    SPI MISO is no use in LCD4884
    //
    xSPinTypeSPI(HD44780_CLK,HD44780_PIN_CLK);
    xSPinTypeSPI(HD44780_MOSI,HD44780_PIN_MOSI);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);

    //
    // Configure SPI  SPI1,ulRate
    //
    xSPIConfigSet((HD44780_SPI), HD44780_SPI_BAUDRATE,
    	SPI_FORMAT_MODE_3 | SPI_DATA_WIDTH8 | SPI_MSB_FIRST | SPI_MODE_MASTER);

    //
    //! \note Enanble SPI SS,test on M0516LBN.other mcu there may need modify.
    //
    xSPISSSet((HD44780_SPI), xSPI_SS_SOFTWARE, xSPI_SS0);
    xSPIEnable(HD44780_SPI);
#else
    //
    // Set Pins Type to GPIO Output
    //

    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CS);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_CLK);
    xGPIOSPinTypeGPIOOutput(HD44780_PIN_MOSI);
#endif

    //
    // Output default value : E disable
    //

    //
    // Set Entry Mode: Interface Data Length, Character Font, Display Line
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_FUNCTION_SET(HD44780_INTERFACE_DATA_LEN |
                                             HD44780_FUNCTION_SET_N_2 |
                                             HD44780_CHARACTER_FONT));

    //
    // Display on & Cursor Blink
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_DISPLAY_CTRL(HD44780_DISPLAY_CTRL_D |
                                             0 |
                                             HD44780_DISPLAY_CTRL_B));

    //
    // Clear LCD
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_CLS);

    //
    // Cursor Move Mode: Increment
    //
    while(HD44780Busy());
    HD44780WriteCmd(HD44780_CMD_ENTRY_MODE_SET(HD44780_ENTRY_MODE_SET_ID_INC |
                                               0));
    
}
コード例 #7
0
ファイル: SPI.cpp プロジェクト: Azz1/RPI_EPI
//Sets the SPIx data mode: SPI_MODE0, SPI_MODE1, SPI_MODE2, SPI_MODE3
void SPIClass::setDataMode(cSPIMode ulMode){
    xSPIDisable(spiPort);
    ulDataFormat = ulMode;
    xSPIConfigSet(spiPort, spiClock, ulDataFormat | ulDataWidth | ulDataMode | xSPI_MODE_MASTER);
    xSPIEnable(spiPort);
}
コード例 #8
0
ファイル: SPI.cpp プロジェクト: Azz1/RPI_EPI
/* Sets the SPIx clock divider relative to the system clock.
 * the dividers available are 2, 4, 8, 16, 32, 64 or 128. The default setting is SPI_CLOCK_DIV4,
 * which sets the clock to 4 MHz like other Arduino boards.
 */
void SPIClass::setClockDivider(uint16_t divider){
    xSPIDisable(spiPort);
    spiClock = 16000000 / divider;
    xSPIConfigSet(spiPort, spiClock, ulDataFormat | ulDataWidth | ulDataMode | xSPI_MODE_MASTER);
    xSPIEnable(spiPort);
}
コード例 #9
0
ファイル: SPI.cpp プロジェクト: Azz1/RPI_EPI
//Sets the order of the bits shifted out of and into the SPIx bus, either LSBFIRST or MSBFIRST.
void SPIClass::setBitOrder(cSPIBitOrder order){
    xSPIDisable(spiPort);
    ulDataMode = order;
    xSPIConfigSet(spiPort, spiClock, ulDataFormat | ulDataWidth | ulDataMode | xSPI_MODE_MASTER);
    xSPIEnable(spiPort);
}