spi_sensor_read.ino
Demuestra la interacción con periféricos externos mediante SPI, común para sensores industriales.
Configure un maestro SPI en Efinity. Conecte un sensor compatible SPI (ej: LM75). Este código es genérico; adapte los comandos específicos a la hoja de datos del sensor. Verifique las señales con un analizador lógico si es necesario.
spi_sensor_read.ino
#include <stdint.h>
#define SPI_BASE 0x80002000
#define SPI_CTRL (*(volatile uint32_t *)(SPI_BASE + 0x00))
#define SPI_DATA (*(volatile uint32_t *)(SPI_BASE + 0x04))
#define SPI_STAT (*(volatile uint32_t *)(SPI_BASE + 0x08))
void spi_cs_low() { SPI_CTRL &= ~0x01; }
void spi_cs_high() { SPI_CTRL |= 0x01; }
uint8_t spi_transfer(uint8_t data) {
SPI_DATA = data;
while (!(SPI_STAT & 0x01)); // Wait for transfer complete
return SPI_DATA;
}
int main() {
uint8_t temp_byte;
while (1) {
spi_cs_low();
spi_transfer(0x00); // Dummy byte to clock out data
temp_byte = spi_transfer(0x00);
spi_cs_high();
// Traitement de temp_byte (à implémenter)
}
return 0;
}