Esempio n. 1
0
/**************************************************************************//**
\brief Opens serial interface and checks memory type.

\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_Open(OFD_Callback_t cb)
{
  ofdCallback = cb;

#if defined(ATMEGA1281) || defined(ATMEGA128RFA1)
  spiDesc.tty       = SPI_CHANNEL_0;
  spiDesc.baudRate  = SPI_CLOCK_RATE_2000;
#elif  defined(ATXMEGA256A3) || defined(ATXMEGA256D3)
  spiDesc.tty       = SPI_CHANNEL_D;
  spiDesc.baudRate  = SPI_CLOCK_RATE_8000;
#endif
  spiDesc.clockMode = SPI_CLOCK_MODE3;
  spiDesc.dataOrder = SPI_DATA_MSB_FIRST;
  spiDesc.callback  = NULL;

  if (-1 == HAL_OpenSpi(&spiDesc))
    if (ofdCallback)
      ofdCallback(OFD_SERIAL_INTERFACE_BUSY);

  GPIO_EXT_MEM_CS_set();
  GPIO_EXT_MEM_CS_make_out();
  ofdFindStorageSpace();
#if EXTERNAL_MEMORY == AT25DF041A
  ofdUnprotectMemorySectors();
#endif
}
Esempio n. 2
0
/**************************************************************************//**
\brief Initializes usart as spi.
******************************************************************************/
void spiMemInit(void)
{
  // Set MSPI mode
  UCSRCSPI = (1 << UMSEL01) | (1 << UMSEL00);
  // Set spi mode 3 and MSB order
  UCSRCSPI |= (1 << UCPOL0) | (1 << UCPHA0);
  // Set sck pin as output
  GPIO_XCK_make_out();
  // Enable receiver and transmitter
  UCSRBSPI = (1 << RXEN0) | (1 << TXEN0);
  // Set maximum baud rate
  UBRRSPI = 0;
  // Set cs pin as output
  GPIO_EXT_MEM_CS_make_out();
  GPIO_EXT_MEM_CS_set();
}