Introduction
The Serial Peripheral Interface (SPI) is high speed serial communication interface. It commonly uses a few wires to connect to its SPI slave devices. In some case it needs only two wires - serial data and serial clock, for instance the SN74HC595N or SN74HC165 parallel in serial output shift registers. It's popular over the parallel port interface that use an 8-bit data port pluses a few control lines, for example the ADC0808 ADC inputs parallel data output.
![]() |
| SPI LED Displays |
There are a lot of in-used SPI slave devices especially the SPI Flash memory for a micro-processor program data space. Some LCD controllers offer many communication protocols such as parallel port, SPI and I2C. However finished LCD module use only serial interfaces such as I2C and SPI.
dsPIC30F2010 Dedicated SPI module
There is one Serial Peripheral Interface (SPI) module inside this chip - that is SPI1. It is full duplex master and slave mode. It transfer clock frequency is up to a quarter of the CPU frequency.
Unlike the 8-bit PIC micro-controllers, the SPI shift registers (SP1BUF) of this chip is 16-bit. There are only two control and status registers.
![]() |
| dsPIC30F SPI Block Diagram |
The programmer just needs to enable the hardware, assign data to the SPI buffer and wait for completion for each data frame.
MikroC SPI Programming for dsPIC30F2010
MikroC supports both hardware and software SPI communication protocol. The I/O pin of SPI interface is fixed with variable Slave Select (SS) pins. One master MCU can communicates with many SPI slave devices. The number of SS pins vary depending the connected SPI slave devices. The software SPI optional in the case where the dedicated SPI port is used for other purposes.
dsPIC30F2010 SPI1 and SN74HC595N LED Interface
I made a simple Serial LED module that used the SN74HC595N Serial-in-Parallel Out Shift Registers. It's simple DIY single-sided PCB module made hands.
![]() |
| Schematic Diagram |
The SPI communication here is a half-duplex master mode because the SN74HC595N is a single direction input device.
![]() |
| Test Program #1 |
![]() |
| Test Program #2 |
![]() |
| Test Program #3 |
For more information about this PCB click here.
MikroC Source Code:
// Chip Select Pin- sbit Chip_Select at LATE3_bit;
- sbit Chip_Select_Direction at TRISE3_bit;
- void SN74595_Send(char _data){
- SPI_Write(_data); // Send high byte via SPI
- Chip_Select = 0; // Select SPI chip
- Chip_Select = 1; // Deselect SPI chip
- }
- void blink(unsigned char counts, unsigned int _times){
- char i = 0;
- while(i<counts){
- SN74595_Send(0);
- Vdelay_ms(_times);
- SN74595_Send(0xFF);
- Vdelay_ms(_times);
- i++;
- }
- }
- void main() {
- char temp=0;
- Chip_Select = 1; // Deselect DAC
- Chip_Select_Direction = 0; // Set CS# pin as Output
- SPI1_Init(); // Initialize SPI module
- blink(10,100);
- Delay_ms(500);
- SN74595_Send(0x00);
- Delay_ms(5000);
- SN74595_Send(0x0F);
- Delay_ms(5000);
- SN74595_Send(0xF0);
- Delay_ms(5000);
- SN74595_Send(0xFF);
- Delay_ms(5000);
- SN74595_Send(0xAA);
- Delay_ms(5000);
- SN74595_Send(0x55);
- Delay_ms(5000);
- SN74595_Send(0x00);
- Delay_ms(5000);
- while (1) { // Endless loop
- SN74595_Send(1<<temp);
- temp++;
- Delay_ms(200);
- if(temp>7) temp = 0;
- }
- }
dsPIC30F2010 SPI1 and SN74HC595N 7-Segment Display Interface
I have one more SPI single digit common anode seven-segment display. I made it many years ago from scrap printer. For more information about this PCB click here.
![]() |
| Schematic Diagram |
In this example I make an up/down counter using this display and two on-board push buttons.
MikroC Source Code:
#define SW4 13- #define SW5 14
- #define CN0 0
- #define CN1 1
- // Chip Select Pin
- sbit Chip_Select at LATE3_bit;
- sbit Chip_Select_Direction at TRISE3_bit;
- void SN74595_Send(char _data){
- SPI_Write(_data); // Send high byte via SPI
- Chip_Select = 0; // Select SPI chip
- Chip_Select = 1; // Deselect SPI chip
- }
- // Common Cathod Segment Data
- const char cc[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
- 0x7F,0x6F,0x77,0x7C,0x58,0x5E,0x79,0x71};
- void show_number(char number){
- SN74595_Send(~cc[number]);
- }
- void main() {
- int temp=0;
- Chip_Select = 1; // Deselect DAC
- Chip_Select_Direction = 0; // Set CS# pin as Output
- SPI1_Init(); // Initialize SPI module
- ADPCFG = 0xFFFF; // configure AN pins as digital
- TRISD = 0; // set direction to be output
- LATD = 0; // turn OFF the PORTD leds
- TRISC = (1<<13)|(1<<14); // RC13 and RC14 As Inputs
- LATC=0; // Clear Buffer
- PORTC=0; // Clear Buffer
- // RC13-CN0 and RC14-CN1 : Enable Pull-Up
- CNPU1 = (1<<1)|(1<<0);
- for(temp=0;temp<16;temp++){
- show_number(temp);
- Delay_ms(1000);
- }
- temp = 0;
- show_number(temp);
- while (1) { // Endless loop
- if((PORTC&(1<<SW4))==0){
- temp++;
- Delay_ms(500);
- }
- if((PORTC&(1<<SW5))==0){
- temp--;
- Delay_ms(500);
- }
- if(temp<0) temp = 0x0F;
- if(temp>0x0F) temp = 0;
- show_number(temp);
- }
- }
For more information about dsPIC30F2010 I/O Programming using MikroC click on this link. I test this program on my DIY dsPIC30F1010 Prototype Board.
![]() |
| Test Program #1 |
![]() |
| Test Program #2 |









No comments:
Post a Comment