Please register or login. There are 0 registered and 483 anonymous users currently online. Current bandwidth usage: 326.30 kbit/s November 30 - 04:07pm EST 
Hardware Analysis
Forums Product Prices

  Latest Topics 

More >>


  You Are Here: 
/ Forums / Programming /

  SPI interfacing with dsPIC30F4013 microcontroller 
 Date Written 
king kong Mar 12, 2010, 10:06pm EST Report Abuse
I am using MPLAB IDE C30 compiler and I am using a dsPIC30F4013 mcu. I am trying to interface using the spi module to send data to a peripheral (audio attenuator) which won't return any data back to the mcu. I will be using C program language. I think I have the initialization correct, but I am stumped on how to actually send data. I have searched in text books, and all over the net for hours and I still can't get it. It seems every example uses a different language, with different libraries so I can't decipher what is going on.
This early code compiles and correctly outputs the printf function.

[CODE]// EE 400/401
// Group #27: Audio normalizer
// SPI interfacing

#include <p30F3014.h>
#include <stdio.h>
_FOSC(CSW_FSCM_OFF & XT_PLL8); // (clock switching and fail safe monitor are disabled &
// crystal connected to OSC1 is the clock source (8x PLL applied, primary oscillator)
_FWDT(WDT_OFF); // Watchdog timer disabled
_FBORPOR(PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN); // Brown-out reset disabled &_____&____& MCLR reset enabled

#define FCY 8000000 // Instruction cycle rate (Osc(4Mhz) x PLL(8) / 4) = 8 MIPS
#define T1Period 800 // T1Period = FCY*100 us = 800

void setup_spi();

int main()


return 0;

void setup_spi()

SPI1CON = 0x063E; // 0000 | 0110 | 0011 | 1110
SPI1STAT = 0x8000; // enable SPI port

printf("To C, or not to C: that is the question.\n");


Want to enjoy fewer advertisements and more features? Click here to become a Hardware Analysis registered user.
king kong Mar 13, 2010, 01:29pm EST Report Abuse
>> Re: SPI interfacing with dsPIC30F4013 microcontroller
Do I just act as though it is a register in a simple program, one that I create myself? It seems that there is a specific command that will do it for me, such as the SPI1CON, SPI1STAT?

king kong Mar 15, 2010, 01:51pm EDT Report Abuse
>> Re: SPI interfacing with dsPIC30F4013 microcontroller
No one knows how to do firmware?

john albrich Mar 16, 2010, 09:48am EDT Report Abuse
>> Re: SPI interfacing with dsPIC30F4013 microcontroller
king kong said:
No one knows how to do firmware?

You're asking like firmware programming experience automatically qualifies someone to know the details of the dsPIC30F4013 development system.

I'm sure lots of us have substantial firmware programming experience as the term "firmware" covers a lot of hardware territory.

However what you're asking is pretty much programming support software and PIC hardware development platform specific.

It's been years since I've done any PIC development work. There's pretty much no way around doing some tedious research with the more sophisticated PIC development systems, and your initial post suggests you have found that out. You have to read the documentation to know what label, attributes, and pre-conditions are associated with the specific serial communication you want with a specific PIC series. The full list of software and hardware programming/init requirements for SPI can vary.

While you're focusing on the programming aspects, don't forget you often have to enable/disable specific hardware jumpers or switches on a given PIC development board in order to get specific SPI (and other) functionality(1). Your programming can be flawless but if you've missed a single bit of the hardware setup it can become quite frustrating.

I think your best bet to find a solution is to keep looking for examples, tutorials, and ask this question on a PIC-specific programming forum.

edited to add this example:
Here's a general example of this type of requirement for one PIC development system.
The dsPICDEM 2 Development Board supports dsPIC30F devices that have multiple
peripheral devices multiplexed on some pins. Therefore, the jumper set up of various
headers depends on which of the dsPIC30F peripherals are used by the application
This section demonstrates how the board is set up for the dsPIC30F2011 device to
support the dsPIC30F2011 example software....

(You also have to watch how you are using the multiplexed devices. "On this device, multiplexing of various peripherals on the pins does not allow the
simultaneous use of....")

micheal scofield Aug 18, 2010, 01:59am EDT Report Abuse
>> Re: SPI interfacing with dsPIC30F4013 microcontroller
hi all,
im desperate, any body plz help me how to start programming my dspic30f4013......
or recommend me a book!!!!




  Topic Tools 
RSS UpdatesRSS Updates

  Related Articles 

A weekly newsletter featuring an editorial and a roundup of the latest articles, news and other interesting topics.

Please enter your email address below and click Subscribe.