Esempio n. 1
0
//*****************************************************************************
//
//! \brief Read AT45DB161 state register
//!
//! \param None
//!
//! This function is to Read AT45DB161 state register
//!
//! \return the value of state register
//
//*****************************************************************************
unsigned char AT45DB161_GetState(void)
{
    unsigned char temp;
    AT45DB161_CS = 0;
    xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_SRRD);
    temp = xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0xff);
    AT45DB161_CS = 1;
    return temp;
}
Esempio n. 2
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;
}
Esempio n. 3
0
//*****************************************************************************
//
//! Spi Master Slave Mode Configure
//!
//! \param None
//!
//! This function configure the SPI as master and slave mode at the same time
//! transfer and receive data
//!
//! \return None
//
//*****************************************************************************
void SpiSlaveModeConfig(void)
{    
    for(i = 0; i < 16; i++)
    {
        ulDestData[i] = xSPISingleDataReadWrite(xSPI1_BASE, ulSourceData[i]);
    }    
}
Esempio n. 4
0
//*****************************************************************************
//
//! \brief Main Memory Page to Buffer Transfer
//!
//! \param ucBufferNum specify the buffer 1 or 2 as the destination.
//! \param usPageAddr specify the page address which you want to read.
//!
//! This function is to transfer data from specified page address of main memory
//! to specified AT45DB161 internal buffer.
//!
//! \return None
//
//*****************************************************************************
void AT45DB161_Mm_to_Buf(unsigned char ucBufferNum, unsigned short usPageAddr)
{
    while(!AT45DB161_WaitReady());
    if (usPageAddr < AT45DB161_PAGES)
    {
        AT45DB161_CS = 0;
        if (ucBufferNum == AT45DB161_BUF1)
        {
            xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_MTB1);
        }
        else
        {
            xSPISingleDataReadWrite(AT45DB161_SPI_PORT, AT45DB161_CMD_MTB2);
        }
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, (unsigned char)(usPageAddr >> 6));
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, (unsigned char)((usPageAddr & 0x003F) << 2));
        xSPISingleDataReadWrite(AT45DB161_SPI_PORT, 0x00);
        AT45DB161_CS = 1;
    }
Esempio n. 5
0
//*****************************************************************************
//
//! !brief callback function of SPI0 interrupt handler.
//!
//! \return None.
//
//*****************************************************************************
unsigned long SPI0Callback(void *pvCBData, unsigned long ulEvent,
                                                    unsigned long ulMsgParam, void *pvMsgData)
{                                      
    ulDestData[Rx_Idx++] = xSPISingleDataReadWrite(xSPI0_BASE, ulSourceData[Tx_Idx++]); 
    if(Tx_Idx == 7)
    {
        ulFlag = 1;
        xSPIIntDisable(xSPI0_BASE, xSPI_INT_RX_FIFO|xSPI_INT_TX_FIFO);
    }
    return 0;
}
Esempio n. 6
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Write command to CH376.
//!
//! \param mCmd command value
//!
//! \details Write command to CH376.
//!
//! \return None.
//
//*****************************************************************************
void    xWriteCH376Cmd( UINT8 mCmd )
{
    //
    // to avoid not asserting CS PIN
    //
    CH376_SPI_CS_SET;
    CH376_SPI_CS_CLR;
    xSPISingleDataReadWrite( CH376_SPI_PORT, mCmd);
    //
    // make sure that read or write cycle must longer than 1.5us
    //
    mDelayuS(2);
}
Esempio n. 7
0
File: xspi.c Progetto: brNX/yarr
//*****************************************************************************
//
//! \brief Gets a data element from the SPI interface.
//!
//! \param ulBase specifies the SPI module base address.
//! \param pulData is a pointer to a storage location for data that was
//! received over the SPI interface.
//! \param ulLen specifies the length of data will be read.
//!
//! This function gets received data from the interface of the specified
//! SPI module and places that data into the location specified by the
//! \e pulData parameter.
//!
//! \note The data width is always 8-bit.
//!
//! \return None.
//
//*****************************************************************************        
void 
SPIDataRead(unsigned long ulBase, unsigned long *pulRData, unsigned long ulLen)
{
    unsigned long i;
    
    //
    // Check the arguments.
    //
    xASSERT((ulBase == SPI0_BASE) || (ulBase == SPI1_BASE));
    xASSERT(pulRData);
    
    for(i = 0; i < ulLen; i++)
    {
        pulRData[i] = xSPISingleDataReadWrite(ulBase, 0xFFFF);
    }
}
Esempio n. 8
0
File: xspi.c Progetto: brNX/yarr
//*****************************************************************************
//
//! \brief Write datas element to the SPI interface.
//!
//! \param ulBase specifies the SPI module base address.
//! \param pulWData is a pointer to a storage location for data that was
//! transmitted over the SPI interface.
//! \param ulLen specifies the length of data will be write.
//!
//! This function transmitted data to the interface of the specified
//! SPI module .
//!
//! \note The data width is always 8-bit.
//!
//! \return None.
//
//*****************************************************************************        
void
SPIDataWrite(unsigned long ulBase, const unsigned long *pulWData, 
             unsigned long ulLen)
{
    unsigned long i;
    volatile unsigned long ulRDataDump;
    
    //
    // Check the arguments.
    //
    xASSERT((ulBase == SPI0_BASE) || (ulBase == SPI1_BASE));
    xASSERT(pulWData);
    
    for(i = 0; i < ulLen; i++)
    {
        ulRDataDump = xSPISingleDataReadWrite(ulBase, pulWData[i]);
    }    
}
Esempio n. 9
0
void
_digitalWrite(unsigned char p, unsigned char d)
{
	int i;
	unsigned char ucData;
    if (d == 1)
      _SPIbuff |= (1 << p);
    else
      _SPIbuff &= ~(1 << p);

    ucData = _SPIbuff;
#if HD44780_SPI_MODE == SPIMODE_HARDWARE
    xGPIOSPinWrite(HD44780_PIN_CS, 0);
    xSPISingleDataReadWrite((HD44780_SPI),ucData);
    xGPIOSPinWrite(HD44780_PIN_CS, 1);
#else

    xGPIOSPinWrite(HD44780_PIN_CS, 0);
    for(i = 0; i < 8; i++)
	{
		//ucData = (0xF7 & (1<<i)) >> i;
		if(ucData & 0x80)
		{
			xGPIOSPinWrite(HD44780_PIN_MOSI, 1);

		}
		else
		{
			xGPIOSPinWrite(HD44780_PIN_MOSI, 0);
		}
		ucData = ucData << 1;

		xGPIOSPinWrite(HD44780_PIN_CLK, 0);
		xSysCtlDelay(1);
		xGPIOSPinWrite(HD44780_PIN_CLK, 1);
	}
    xGPIOSPinWrite(HD44780_PIN_CS, 1);
#endif
}
Esempio n. 10
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Read data from CH376.
//!
//! \param None
//!
//! \details Read data from CH376.
//!
//! \return data read out from CH376.
//
//*****************************************************************************
UINT8 xReadCH376Data( void )
{
    return(xSPISingleDataReadWrite(CH376_SPI_PORT, 0xFF));
}
Esempio n. 11
0
File: CH376.c Progetto: AlexGora/cox
//*****************************************************************************
//
//! \brief Write data to CH376.
//!
//! \param mData data value
//!
//! \details Write data to CH376.
//!
//! \return None.
//
//*****************************************************************************
void    xWriteCH376Data( UINT8 mData )
{
    xSPISingleDataReadWrite( CH376_SPI_PORT, mData);
}
Esempio n. 12
0
uint8_t wizchip_read()
{
   return xSPISingleDataReadWrite(WIZCHIP_SPI_BASE,0xFF);
}
Esempio n. 13
0
void  wizchip_write(uint8_t wb)
{
   xSPISingleDataReadWrite(WIZCHIP_SPI_BASE,wb);
}
Esempio n. 14
0
File: SPI.cpp Progetto: Azz1/RPI_EPI
// Writes (and reads) a single byte to SPIx
uint8_t SPIClass::transfer(uint8_t value){
    unsigned long ulReadTemp = xSPISingleDataReadWrite(spiPort, value);
    return ulReadTemp;
}