|
|
5 месяцев назад | |
|---|---|---|
| .. | ||
| .settings | 6 месяцев назад | |
| board | 6 месяцев назад | |
| figures | 1 год назад | |
| packages | 6 месяцев назад | |
| rzn | 6 месяцев назад | |
| rzn_cfg | 6 месяцев назад | |
| rzn_gen | 6 месяцев назад | |
| script | 6 месяцев назад | |
| src | 6 месяцев назад | |
| .api_xml | 1 год назад | |
| .config | 6 месяцев назад | |
| .cproject | 6 месяцев назад | |
| .gitignore | 1 год назад | |
| .project | 1 год назад | |
| .secure_azone | 1 год назад | |
| .secure_rzone | 6 месяцев назад | |
| .secure_xml | 6 месяцев назад | |
| Kconfig | 6 месяцев назад | |
| README.md | 5 месяцев назад | |
| README_zh.md | 5 месяцев назад | |
| SConscript | 6 месяцев назад | |
| SConstruct | 1 год назад | |
| buildinfo.ipcf | 6 месяцев назад | |
| buildinfo.json | 6 месяцев назад | |
| configuration.xml | 6 месяцев назад | |
| envsetup.sh | 1 год назад | |
| mklinks.bat | 1 год назад | |
| mklinks.sh | 1 год назад | |
| ozone_scons.jdebug | 1 год назад | |
| project.ewd | 6 месяцев назад | |
| project.ewp | 6 месяцев назад | |
| project.ewt | 6 месяцев назад | |
| project.eww | 1 год назад | |
| rtconfig.h | 6 месяцев назад | |
| rtconfig.py | 1 год назад | |
| rzn_cfg.txt | 6 месяцев назад | |
| template.ewd | 1 год назад | |
| template.ewp | 6 месяцев назад | |
| template.eww | 1 год назад | |
English | 中文
This example demonstrates how to use the RT-Thread SCI_SPI framework on the EtherKit.
The EtherKit board has a PMOD interface, which is connected to the SCI_SPI3 of the R9A07G084M08GBG chip.
Open the FSP tool, create a new stack, and select r_sci_spi3:
In RT-Thread Settings, enable SCI hardware and configure SCI3 mode as SPI:
This example uses the RT-Thread SCI driver framework to perform a loopback test on the PMOD interface (connecting PMOD's SPI3_MOSI to SPI3_MISO). The code is as follows:
void spi_loop_test(void)
{
#define TEXT_NUMBER_SIZE 1024
#define SPI_BUS_NAME "sci3s"
#define SPI_NAME "spi30"
static uint8_t sendbuf[TEXT_NUMBER_SIZE] = {0};
static uint8_t readbuf[TEXT_NUMBER_SIZE] = {0};
for (int i = 0; i < sizeof(readbuf); i++)
{
sendbuf[i] = i;
}
static struct rt_spi_device *spi_dev = RT_NULL;
struct rt_spi_configuration cfg;
rt_hw_sci_spi_device_attach(SPI_BUS_NAME, SPI_NAME, NULL);
cfg.data_width = 8;
cfg.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB | RT_SPI_NO_CS;
cfg.max_hz = 1 * 1000 * 1000;
spi_dev = (struct rt_spi_device *)rt_device_find(SPI_NAME);
if (RT_NULL == spi_dev)
{
rt_kprintf("spi sample run failed! can't find %s device!\n", SPI_NAME);
return;
}
rt_spi_configure(spi_dev, &cfg);
rt_kprintf("%s send:\n", SPI_NAME);
for (int i = 0; i < sizeof(sendbuf); i++)
{
rt_kprintf("%02x ", sendbuf[i]);
}
rt_spi_transfer(spi_dev, sendbuf, readbuf, sizeof(sendbuf));
rt_kprintf("\n\n%s rcv:\n", SPI_NAME);
for (int i = 0; i < sizeof(readbuf); i++)
{
if (readbuf[i] != sendbuf[i])
{
rt_kprintf("SPI test fail!!!\n");
break;
}
else
rt_kprintf("%02x ", readbuf[i]);
}
rt_kprintf("\n\n");
rt_kprintf("SPI test end\n");
}
mklinks.bat to create symbolic links between RT-Thread and the libraries folder. Then, use the Env tool to generate the IAR project. Finally, double-click project.eww to open the IAR project and compile it.After compilation, connect the development board’s JLink interface to the PC and download the firmware to the development board.
When using a serial tool, you can observe that the data sent and received in the SPI loopback test matches: