Esempio n. 1
0
/** 
 * \brief Deselect one external SerialFlash component.
 *
 * \param mem_id  The SerialFlash index number.
 */
void at25dfx_spi_deselect_device(uint8_t mem_id)
{
	UNUSED(mem_id);
#if defined( AT25DFX_USES_SPI_MASTER_SERVICE)
	#if (AT25DFX_MEM_CNT==1)
	spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE1);
	#else
	switch(mem_id) {
	case 1:
		spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE1);
		break;

	case 2:
		spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE2);
		break;

	case 3:
		spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE3);
		break;

	case 4:
		spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE4);
		break;

	default:
		/* unhandled_case(id); */
		return;
	}
	#endif

/* Implementation with USART in SPI mode service */
#elif defined(AT25DFX_USES_USART_SPI_SERVICE)
	#if (AT25DFX_MEM_CNT==1)
	usart_spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE1);
	#else
	switch(mem_id) {
	case 1:
		usart_spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE1);
		break;

	case 2:
		usart_spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE2);
		break;

	case 3:
		usart_spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE3);
		break;

	case 4:
		usart_spi_deselect_device(AT25DFX_SPI_MODULE, &AT25DFX_DEVICE4);
		break;

		default:
			/* unhandled_case(id); */
			return;
		}
#endif
#endif
	}
Esempio n. 2
0
/*
*	Write to the switch registers
*
*/
int switch_write(uint8_t param1, uint8_t param2)
{
	uint8_t reg[3];

	if (param1 < 128) {
		reg[0] = 64;
		} else {
		reg[0] = 65;
	}

	reg[1] = param1 << 1;
	reg[2] = param2;

	/* Select the DF memory to check. */
	usart_spi_select_device(USART_SPI, &USART_SPI_DEVICE);

	/* Send the Manufacturer ID Read command. */
	usart_spi_write_packet(USART_SPI, reg, 3);

	/* Deselect the checked DF memory. */
	usart_spi_deselect_device(USART_SPI, &USART_SPI_DEVICE);
	for(int x = 0;x<100000;x++);

	return switch_read(param1);
}
Esempio n. 3
0
/*
*	Read from the switch registers
*
*/
int switch_read(uint8_t param1)
{
	uint8_t reg[2];

	if (param1 < 128) {
		reg[0] = 96;
		} else {
		reg[0] = 97;
	}

	reg[1] = param1 << 1;

	/* Select the DF memory to check. */
	usart_spi_select_device(USART_SPI, &USART_SPI_DEVICE);

	/* Send the Manufacturer ID Read command. */
	usart_spi_write_packet(USART_SPI, reg, 2);

	/* Receive Manufacturer ID. */
	usart_spi_read_packet(USART_SPI, reg, 1);

	/* Deselect the checked DF memory. */
	usart_spi_deselect_device(USART_SPI, &USART_SPI_DEVICE);

	return reg[0];
}
Esempio n. 4
0
/*! \brief SPI slave tranfers data to Usart SPI master
 */
static bool spi_slave_transfer(void)
{
	/* Select the Slave device */
	usart_spi_select_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Put the slave read command in master tx buffer */
	data_master_tx[0] = SLAVE_RD_CMD;

	count = 0;

	/* Send the Read command */
	usart_spi_write_packet(USART_SPI_EXAMPLE, data_master_tx, 1);

	/* Receive data from slave */
	usart_spi_read_packet(USART_SPI_EXAMPLE, data_master_rx,
			DATA_BUFFER_SIZE);

	/* Deselect the Slave device  */
	usart_spi_deselect_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Check the master received data with slave tx data */
	for (uint8_t i = 0; i < DATA_BUFFER_SIZE; i++) {
		if (data_master_rx[i] == data_slave_tx[i]) {
			continue;
		} else {
			return false;
		}
	}

	return true;
}
Esempio n. 5
0
/*! \brief Usart configured as SPI master transfers data to SPI slave.
 */
static bool spi_usart_master_transfer(void)
{
	/* Select the Slave device */
	usart_spi_select_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Send the data to slave */
	usart_spi_write_packet(USART_SPI_EXAMPLE, data_master_tx,
			DATA_BUFFER_SIZE);

	/* Deselect the Slave device  */
	usart_spi_deselect_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Check the Slave received data with master tx data */
	for (uint8_t i = 0; i < DATA_BUFFER_SIZE; i++) {
		if (data_master_tx[i] == data_slave_rx[i]) {
			continue;
		} else {
			return false;
		}
	}

	return true;
}
static bool usart_spi_at45dbx_mem_check(void)
{
	/* Select the DF memory to check. */
	usart_spi_select_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Send the Manufacturer ID Read command. */
	usart_spi_write_packet(USART_SPI_EXAMPLE, data, 1);

	/* Receive Manufacturer ID. */
	usart_spi_read_packet(USART_SPI_EXAMPLE, data, DATA_BUFFER_SIZE);

	/* Extract the Manufacturer ID. */
	manufacturer_id = data[0];

	/* Deselect the checked DF memory. */
	usart_spi_deselect_device(USART_SPI_EXAMPLE, &USART_SPI_DEVICE_EXAMPLE);

	/* Check the Manufacturer id. */
	if (manufacturer_id == ATMEL_MANUFACTURER_ID) {
		return true;
	} else {
		return false;
	}
}