mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
add examples
This commit is contained in:
parent
265d41b6a3
commit
4128624f93
112 changed files with 158017 additions and 0 deletions
24
RTL00_SDKV35a/example_sources/spi_twoboard/readme.txt
Normal file
24
RTL00_SDKV35a/example_sources/spi_twoboard/readme.txt
Normal file
|
@ -0,0 +1,24 @@
|
|||
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, we use config SPI_IS_AS_MASTER to decide if device is master or slave.
|
||||
If SPI_IS_AS_MASTER is 1, then device is master.
|
||||
If SPI_IS_AS_MASTER is 0, then device is slave.
|
||||
|
||||
We connect wires as below:
|
||||
master's MOSI (PC_2) connect to slave's MOSI (PC_2)
|
||||
master's MISO (PC_3) connect to slave's MISO (PC_3)
|
||||
master's SCLK (PC_1) connect to slave's SCLK (PC_1)
|
||||
master's CS (PC_0) connect to slave's CS (PC_0)
|
||||
|
||||
This example shows master sends data to slave.
|
||||
We bootup slave first, and then bootup master.
|
||||
Then log will presents that master sending data to slave.
|
64
RTL00_SDKV35a/example_sources/spi_twoboard/src/main.c
Normal file
64
RTL00_SDKV35a/example_sources/spi_twoboard/src/main.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* 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 "main.h"
|
||||
#include "spi_api.h"
|
||||
|
||||
#define SPI_IS_AS_MASTER 1
|
||||
|
||||
// SPI0
|
||||
#define SPI0_MOSI PC_2
|
||||
#define SPI0_MISO PC_3
|
||||
#define SPI0_SCLK PC_1
|
||||
#define SPI0_CS PC_0
|
||||
|
||||
/**
|
||||
* @brief Main program.
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void main(void)
|
||||
{
|
||||
int TestingTimes = 10;
|
||||
int Counter = 0;
|
||||
int TestData = 0;
|
||||
|
||||
#if SPI_IS_AS_MASTER
|
||||
spi_t spi_master;
|
||||
|
||||
SPI0_IS_AS_SLAVE = 0;
|
||||
spi_init(&spi_master, SPI0_MOSI, SPI0_MISO, SPI0_SCLK, SPI0_CS);
|
||||
|
||||
DBG_SSI_INFO("--------------------------------------------------------\n");
|
||||
for(Counter = 0, TestData=0xFF; Counter < TestingTimes; Counter++) {
|
||||
spi_master_write(&spi_master, TestData);
|
||||
DBG_SSI_INFO("Master write: %02X\n", TestData);
|
||||
TestData--;
|
||||
}
|
||||
spi_free(&spi_master);
|
||||
|
||||
#else
|
||||
spi_t spi_slave;
|
||||
|
||||
SPI0_IS_AS_SLAVE = 1;
|
||||
spi_init(&spi_slave, SPI0_MOSI, SPI0_MISO, SPI0_SCLK, SPI0_CS);
|
||||
|
||||
DBG_SSI_INFO("--------------------------------------------------------\n");
|
||||
for(Counter = 0, TestData=0xFF; Counter < TestingTimes; Counter++) {
|
||||
DBG_SSI_INFO(ANSI_COLOR_CYAN"Slave read : %02X\n"ANSI_COLOR_RESET,
|
||||
spi_slave_read(&spi_slave));
|
||||
TestData--;
|
||||
}
|
||||
spi_free(&spi_slave);
|
||||
#endif
|
||||
|
||||
DBG_SSI_INFO("SPI Demo finished.\n");
|
||||
for(;;);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue