Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

How to use wiringPi function in SP7021 platform
This is modified from unofficial mirror/fork of wiringPi to support SP7021 board (Sunplus evaluation board). Because of SP7021 hardware is different from Raspberry Pi so that there are some hardware-related function would not be supported. (like edge/pad drive/pwm-bal/pwm-ms ...)
WiringPi is a simple and easy-to-use function library, through wiringPi, chips such as SPI, UART and I2C can be extended. The GPIO control also become very simple through wiringPi.
If user is familiar to Raspberry Pi, mostly you will also know the wiringPi very well. The wiringPi in SP7021 function will help you quickly control peripherals of SP7021 development board.
Please follow below step to operate:

  1. Environment

Platform: Bpi-F2S
OS: Raspbian + SP7021 linux kernel

  1. Download wiringPi source code

git clone https://github.com/sunplus-plus1/wiringpiforsp7021.git

  1. Set your cross compiler path from build script file

cd wiringpiforsp7021
nano build

  1. Build code

./build debian

  1. Install deb package

cd debian-template
sudo dpkg –i wiringpi-2.61-1.deb

  1. Check install result by "gpio –v" and "gpio readall"



7. Command line control method
7.1 Set pin0 to gpio output
gpio mode 0 output
7.2 pin0 gpio read
gpio read 0
7.3 pin0 gpio set high
gpio write 0 1
7.4 Set pin2 as pwm0
gpio mode 0 pwm0
7.5 Set pin2 pwm clock
gpio pwmc 2 100 /* pwm0 clock = 100Hz */
7.6 Set pin2 pwm duty
gpio pwm 2 100 /* duty ratio = 100/255 =39.2% */
8. Programming example
#include <stdio.h>
#include <wiringPi.h>
// LED Pin - wiringPi pin 0 is SP7021 pin 18.
#defineLED0
// Set pin2 to pwm mode - wiringPi pin 2 is SP7021 pin 19.
#definePWM2
int main (void)
{
printf ("Raspberry Pi blink\n") ;
wiringPiSetup () ;
pinMode (LED, OUTPUT) ;
pinMode (PWM, PWM_OUTPUT) ;
pwmWrite (PWM, 100) ; // duty ratio = 100/255 =39.2%
for (;(wink)
{
digitalWrite (LED, HIGH) ;// On
delay (500) ; // mS
digitalWrite (LED, LOW) ; // Off
delay (500) ; // mS
}
return 0 ;
}
Execute result:

  • No labels