mirror of
https://github.com/pvvx/rtl00TstMinAmebaV35a.git
synced 2025-07-31 20:31:06 +00:00
first commit
This commit is contained in:
commit
c399bf5be0
806 changed files with 421674 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
Example Description
|
||||
|
||||
This example describes how to use SPI read/write by mbed api.
|
||||
|
||||
|
||||
The SPI Interface provides a "Serial Peripheral Interface" Master.
|
||||
|
||||
This interface can be used for communication with SPI slave devices,
|
||||
such as FLASH memory, LCD screens and other modules or integrated circuits.
|
||||
|
||||
In this example, it use 2 sets of SPI. One is master, the other is slave.
|
||||
By default it use SPI0 as slave, and use SPI2 as master.
|
||||
So we connect them as below:
|
||||
Connect SPI0_MOSI (PC_2) to SPI2_MOSI (PA_1)
|
||||
Connect SPI0_MISO (PC_3) to SPI2_MISO (PA_0)
|
||||
Connect SPI0_SCLK (PC_1) to SPI2_SCLK (PA_2)
|
||||
Connect SPI0_CS (PC_0) to SPI2_CS (PA_4)
|
||||
|
||||
Because some GPIOA are used as SDIO purpose which has higher priority.
|
||||
So we need pull high PA_7 when device boot up.
|
||||
Connect PA_7 to 3V3
|
||||
|
||||
After boot up, the master will send data to slave and shows result on LOG_OUT.
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Routines to access hardware
|
||||
*
|
||||
* Copyright (c) 2014 Realtek Semiconductor Corp.
|
||||
*
|
||||
* This module is a confidential and proprietary property of RealTek and
|
||||
* possession or use of this module requires written permission of RealTek.
|
||||
*/
|
||||
|
||||
#include "device.h"
|
||||
#include "diag.h"
|
||||
#include "main.h"
|
||||
#include "spi_api.h"
|
||||
|
||||
#define FakeMbedAPI 1
|
||||
|
||||
// SPI0 (S0)
|
||||
#define SPI0_MOSI PC_2
|
||||
#define SPI0_MISO PC_3
|
||||
#define SPI0_SCLK PC_1
|
||||
#define SPI0_CS PC_0
|
||||
|
||||
// SPI1 (S1)
|
||||
#define SPI1_MOSI PB_6
|
||||
#define SPI1_MISO PB_7
|
||||
#define SPI1_SCLK PB_5
|
||||
#define SPI1_CS PB_4
|
||||
|
||||
#if 1
|
||||
// SPI2 (S2) for DEV 3V0
|
||||
// Please note that PA_7 need pull high before using GPIOA group
|
||||
#define SPI2_MOSI PA_1
|
||||
#define SPI2_MISO PA_0
|
||||
#define SPI2_SCLK PA_2
|
||||
#define SPI2_CS PA_4
|
||||
#else
|
||||
// SPI2 (S2)
|
||||
#define SPI2_MOSI PD_2
|
||||
#define SPI2_MISO PD_3
|
||||
#define SPI2_SCLK PD_1
|
||||
#define SPI2_CS PD_0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Main program.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
spi_t spi_master;
|
||||
spi_t spi_slave;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
#if FakeMbedAPI
|
||||
|
||||
/* SPI0 is as Slave */
|
||||
//SPI0_IS_AS_SLAVE = 1;
|
||||
|
||||
spi_init(&spi_master, SPI2_MOSI, SPI2_MISO, SPI2_SCLK, SPI2_CS);
|
||||
spi_format(&spi_master, 8, 0, 0);
|
||||
spi_frequency(&spi_master, 200000);
|
||||
spi_init(&spi_slave, SPI0_MOSI, SPI0_MISO, SPI0_SCLK, SPI0_CS);
|
||||
spi_format(&spi_slave, 8, 0, 1);
|
||||
|
||||
int TestingTimes = 10;
|
||||
int Counter = 0;
|
||||
int TestData = 0;
|
||||
int ReadData = 0;
|
||||
|
||||
int result = 1;
|
||||
|
||||
/**
|
||||
* Master read/write, Slave read/write
|
||||
*/
|
||||
DBG_SSI_INFO("--------------------------------------------------------\n");
|
||||
for(Counter = 0, TestData=0x01; Counter < TestingTimes; Counter++)
|
||||
{
|
||||
ReadData = spi_master_write(&spi_master, TestData);
|
||||
DBG_SSI_INFO("Master write: %02X, read: %02X\n", TestData, ReadData);
|
||||
if (TestData - 1 != ReadData) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
TestData++;
|
||||
|
||||
spi_slave_write(&spi_slave, TestData);
|
||||
ReadData = spi_slave_read(&spi_slave);
|
||||
DBG_SSI_INFO(ANSI_COLOR_CYAN"Slave write: %02X, read: %02X\n"ANSI_COLOR_RESET, TestData, ReadData);
|
||||
if (TestData - 1 != ReadData) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
TestData++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Master write, Slave read
|
||||
*/
|
||||
DBG_SSI_INFO("--------------------------------------------------------\n");
|
||||
for(Counter = 0, TestData=0xFF; Counter < TestingTimes; Counter++)
|
||||
{
|
||||
spi_master_write(&spi_master, TestData);
|
||||
ReadData = spi_slave_read(&spi_slave);
|
||||
DBG_SSI_INFO("Master write: %02X\n", TestData);
|
||||
DBG_SSI_INFO(ANSI_COLOR_CYAN"Slave read : %02X\n"ANSI_COLOR_RESET, ReadData);
|
||||
if (TestData != ReadData) {
|
||||
result = 0;
|
||||
}
|
||||
|
||||
TestData--;
|
||||
}
|
||||
|
||||
spi_free(&spi_master);
|
||||
spi_free(&spi_slave);
|
||||
|
||||
DBG_SSI_INFO("SPI Demo finished.\n");
|
||||
|
||||
printf("\r\nResult is %s\r\n", (result) ? "success" : "fail");
|
||||
|
||||
for(;;);
|
||||
|
||||
#else // mbed SPI API emulation
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue