Beispiel #1
0
//*****************************************************************************
//
//! \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);
	
}
Beispiel #2
0
//*****************************************************************************
//
//! \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);
}
Beispiel #3
0
//*****************************************************************************
//
//! \brief Initialize TC77 
//!
//! \param ulClock specifies the SPI Clock Rate
//!
//! This function is to initialize the MCU as master and specified SPI port.Set
//! TC77_PIN_SPI_CS as CS, TC77_PIN_SPI_CLK as CLK, TC77_PIN_SPI_MISO ->MISO and 
//! TC77_PIN_SPI_MOSI->MOSI,most of all it check the first conversion is finished 
//! or not in order to execute the following operation.
//! 
//! \return None.
//
//*****************************************************************************
void
TC77Init(unsigned long ulSpiClock)
{
    short sReadValue = 0;
    
    //
    // The max clock rate of TC77 is 7M Hz acoording to Datasheet, Otherwise
    // it will generate  bigger error
    //
    xASSERT((ulSpiClock > 0) && (ulSpiClock < 7000000));
    
    //
    // Enable the GPIOx port which is connected with tc77 
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(TC77_PIN_SPI_CS));
    
    //
    // Enable the SPIx which is connected with tc77
    //
    xSysCtlPeripheralEnable2(TC77_PIN_SPI_PORT);
    
    //
    // Set TC77_PIN_SPI_CS as a chip select pin and set it as OUT_MODE
    //
    xGPIOSPinDirModeSet(TC77_PIN_SPI_CS, xGPIO_DIR_MODE_OUT);
    
    //
    // Set TC77_PIN_SPI_CLK as SPIx.CLK
    //
    xSPinTypeSPI(TC77_SPI_CLK, TC77_PIN_SPI_CLK);
    
    //
    // Set TC77_PIN_SPI_MISO as SPIx.MISO
    //
    xSPinTypeSPI(TC77_SPI_MISO, TC77_PIN_SPI_MISO);
    
    //
    // Configure MCU as a master device , 16 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(TC77_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_0 |
                                                       xSPI_DATA_WIDTH16 |
                                                        xSPI_MODE_MASTER |
                                                           xSPI_MSB_FIRST);
    //
    // Disable TC77 when Power up
    //
    xGPIOSPinWrite(TC77_PIN_SPI_CS, 1);

    //
    // Wait for the first conversion completed
    //
    while(!(0x0004 & sReadValue))
    {
        sReadValue = TC77TemperRead();
    }
}
Beispiel #4
0
//*****************************************************************************
//
//! \brief Initialize AT45DB161 and SPI
//!
//! \param ulSpiClock specifies the SPI Clock Rate
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//! After SPI and port was configured, the mcu send a AT45DB161_CMD_SRRD command
//! to get the page size of AT45DB161 to get prepareed for the followed read and
//! write operations.
//!
//! \return None.
//
//*****************************************************************************
void AT45DB161_Init(unsigned long ulSpiClock)
{
    unsigned char tmp;
    xASSERT((ulSpiClock > 0) && (ulSpiClock < AT45DB161_MAX_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_CS_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MISO));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(AT45DB161_MOSI));
    xSysCtlPeripheralEnable2(AT45DB161_SPI_PORT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xGPIOSPinDirModeSet(AT45DB161_CS_PIN, xGPIO_DIR_MODE_OUT);
#if (AT45DB161_WRITE_PROTECT < 1)
    xGPIOSPinDirModeSet(FLASH_PIN_WRITE_PROTECT, xGPIO_DIR_MODE_OUT);
    xGPIOSPinWrite(FLASH_PIN_WRITE_PROTECT, 0);
#endif
    //
    // PD1 as SPI2.CLK
    //
    xSPinTypeSPI(SPI_CLK, AT45DB161_SCK);
    //
    // PD2 as SPI2.MISO
    // MISO20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MISO, AT45DB161_MISO);
    //
    // PD3 as SPI2.MOSI
    // MOSI20 => SPI0MISO
    //
    xSPinTypeSPI(SPI_MOSI, AT45DB161_MOSI);

    //xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    //
    //! Set SPI mode.
    //
    xSPIConfigSet(AT45DB161_SPI_PORT, ulSpiClock, SPI_MODE_MASTER |
                  SPI_MSB_FIRST |
                  SPI_2LINE_FULL |
                  SPI_DATA_WIDTH8 |
                  SPI_FORMAT_MODE_4);
    SPISSModeConfig(AT45DB161_SPI_PORT, SPI_CR1_SSM);
    SPISSIConfig(AT45DB161_SPI_PORT, SPI_CR1_SSI);
    SPIEnble(AT45DB161_SPI_PORT);
    AT45DB161_CS = 1;
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    xSysCtlDelay(100000);
    AT45DB161_CS = 0;
    //
    //! Read AT45DB161 state register to get the page size.
    //
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_SRRD);
    tmp = xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xFF);
    if(tmp & AT45DB161_PGSZ) AT45DB161_PageSize = 512;
    AT45DB161_CS = 1;
}
Beispiel #5
0
//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);
}
Beispiel #6
0
//////////////////////////////////////////////////////////////////////////////
// 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));
}
Beispiel #7
0
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;
    }
}
Beispiel #8
0
//*****************************************************************************
//
//! Ininite the SPI case which is needed
//!
//! \param None
//!
//! This function ininite the SPI including clock source and enable spi 
//!
//! \return none
//
//*****************************************************************************
void SpiReceiveTransferInit(void)
{
    //
    // Set SysClk 36MHz using Extern 12M oscillator
    //
    xSysCtlClockSet(12000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_25MHZ);
    //
    // Enable Peripheral SPI0
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI1);
    
    //
    // Configure Some GPIO pins as SPI Mode
    //
    xSPinTypeSPI(SPI1CLK(1), PA5);
    xSPinTypeSPI(SPI1MOSI(1), PA7);
    xSPinTypeSPI(SPI1MISO(1), PA6);
    xSPinTypeSPI(SPI1CS(1), PA4);

    xSPIConfigSet(SPI1_BASE, 200000, xSPI_MOTO_FORMAT_MODE_0 | xSPI_DATA_WIDTH8 | 
                             xSPI_MSB_FIRST | xSPI_MODE_SLAVE);

}
Beispiel #9
0
//*****************************************************************************
//
//! \brief MCU communication port initialize
//!
//! \param None
//!
//! \return None.
//
//*****************************************************************************
void	CH376PortInit( void )
{
#ifdef CH376_INT_WIRE
    xSysCtlPeripheralEnable2(CH376_INT_PORT);
    xGPIOSPinDirModeSet(CH376_INT_PIN, xGPIO_DIR_MODE_IN); //pass
    xGPIOSPinWrite(CH376_INT_PIN, 1);
#endif
#ifdef CH376_USE_HARDWARE_SPI
    xSysCtlPeripheralEnable2(CH376_SPI_CS_PORT);
    xGPIOSPinDirModeSet(CH376_SPI_CS_PIN, xGPIO_DIR_MODE_OUT);
    xSysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO);
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SCK));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MISO));
    xSysCtlPeripheralEnable2(CH376_SPI_PORT);

    xSPinTypeSPI(CH376SPI_CLK, CH376_SCK);
    xSPinTypeSPI(CH376SPI_MISO, CH376_MISO);
    xSPinTypeSPI(CH376SPI_MOSI, CH376_MOSI);

    xSPIConfigSet(CH376_SPI_PORT, CH376_CLK_FREQ, SPI_MODE_MASTER |
    		            xSPI_MOTO_FORMAT_MODE_3 |
    		            xSPI_MODE_MASTER |
    		            xSPI_MSB_FIRST |
    		            xSPI_DATA_WIDTH8);
//    SPISSModeConfig(CH376_SPI_PORT, SPI_CR1_SSM);
//    SPISSIConfig(CH376_SPI_PORT, SPI_CR1_SSI);
    xSPISSSet( CH376_SPI_PORT, xSPI_SS_SOFTWARE, xSPI_SS0 );
    SPIEnble(CH376_SPI_PORT);
    CH376_SPI_CS_SET;
#endif  //End of CH376_USE_HARDWARE_SPI define

#ifdef CH376_USE_SOFTWARE_SPI
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SCK_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MISO_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_MOSI_PIN));
    xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(CH376_SPI_CS_PIN));

    xGPIOSPinDirModeSet(CH376_SPI_CS_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_SCK_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_MOSI_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_MISO_PIN, xGPIO_DIR_MODE_IN);
    CH376_SPI_CS_SET;
#endif  //End of CH376_USE_SOFTWARE_SPI define

#ifdef CH376_USE_PARALLEL
    xSysCtlPeripheralEnable2(CH376_WR_PORT);
    xSysCtlPeripheralEnable2(CH376_RD_PORT);
    xSysCtlPeripheralEnable2(CH376_A0_PORT);
    xSysCtlPeripheralEnable2(CH376_PCS_PORT);
    xSysCtlPeripheralEnable2(CH376_DATA_PORT);
    xGPIOSPinDirModeSet(CH376_WR_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_RD_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_A0_PIN, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(CH376_PCS_PIN, xGPIO_DIR_MODE_OUT);
    xGPIODirModeSet( CH376_DATA_PORT, 0xFF, xGPIO_DIR_MODE_IN );
    CH376_PCS_SET;
    CH376_WR_SET;
    CH376_RD_SET;
    CH376_A0_CLR;
#endif  //End of CH376_USE_PARALLEL define

}
Beispiel #10
0
//*****************************************************************************
//
//! \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));
    
}
Beispiel #11
0
//*****************************************************************************
//
//! \brief Init the UC1701 LCD.
//!
//! \param ulSpiClock SPI clock to select.
//!
//! This function initialize the mcu SPI as master and specified SPI port.
//!
//! \return None.
//
//*****************************************************************************
void UC1701Init(unsigned long ulSpiClock)
{
    //
    // Enable the GPIOx port which is connected with UC1701
    //
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_CLK));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_CS));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_SPI_MOSI));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_CD));
    xSysCtlPeripheralEnable(xGPIOSPinToPort(LCD_PIN_RESET));
    
    //
    // Enable the SPIx which is connected with UC1701
    //
    xSysCtlPeripheralEnable2(LCD_PIN_SPI_PORT);
    xSysCtlPeripheralReset2(LCD_PIN_SPI_PORT);
    //
    // Set the chip select pin as OUT_MODE
    //
    xGPIOSPinDirModeSet(LCD_PIN_SPI_CS, xGPIO_DIR_MODE_OUT);
    //
    // Set the chip reset pin as OUT_MODE
    //
    xGPIOSPinDirModeSet(LCD_PIN_CD, xGPIO_DIR_MODE_OUT);
    xGPIOSPinDirModeSet(LCD_PIN_RESET, xGPIO_DIR_MODE_OUT);
    
    xSPinTypeSPI(SPI_CLK, LCD_PIN_SPI_CLK);
    xSPinTypeSPI(SPI_MOSI, LCD_PIN_SPI_MOSI);
    
    //
    // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0
    //
    xSPIConfigSet(LCD_PIN_SPI_PORT, ulSpiClock, xSPI_MOTO_FORMAT_MODE_1 |
                                                xSPI_MODE_MASTER | 
                                                xSPI_MSB_FIRST |
                                                xSPI_DATA_WIDTH8);
    //
    // Disable UC1701 when Power up
    //
    xGPIOSPinWrite(LCD_PIN_SPI_CS, 1);

    //
    // Reset the chip
    //
    xGPIOSPinWrite(LCD_PIN_RESET, 0);
    delay_ms(2);
    xGPIOSPinWrite(LCD_PIN_RESET, 1);
    delay_ms(6);

    //
    // Initial Configuration
    //
    UC1701CmdWrite(0xe2);//System Reset
	UC1701CmdWrite(0x2c);//Power Rise Step1
	delay_ms(8);
	UC1701CmdWrite(0x2e);//Power Rise Step2
	delay_ms(8);
	UC1701CmdWrite(0x2f);//Power Rise Step3
	delay_ms(8);
	UC1701CmdWrite(0x23);
	UC1701DoubleCmdWrite(0x81, 0x1f);//Set LCD resistor ratio

	UC1701CmdWrite(0xa2);//Bias 1/9
	UC1701CmdWrite(0xc0);//Set COM Direction
	UC1701CmdWrite(0xa0);//Set SEG Direction
	UC1701CmdWrite(0x40);//Set Scroll Line: the first line
	UC1701CmdWrite(0xaf);//Display Enable

}
Beispiel #12
0
//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);
}
Beispiel #13
0
/* 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);
}
Beispiel #14
0
//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);
}