PICkit3--PIC16F690 and SPI data transmittion

Thread Starter

Leo Silver

Joined Apr 27, 2016
46
Hi everyone,

I have the PICDEM Lab development kit of Microchip tools and I would like to control a peripheral (at first another MCU PIC16F88) through the SPI port of the PIC16F690.
I see that there aren't any functions at either xc8 or Hitech compiler to support the SPI module for this microcontroller but I found some people who have worked around building their own protocols that I want to try to adapt to my system.
As I am just starting with programming a MCU I have two basic questions:
1) I am using the Pickit3 to power, debug and download my code to the microcontroller.
Could I just program first the slave microcontroller then disconnect the Pickit from the slave and connect it to the master, program the master and make the connection for the data transfer? Also, can I just power my slave from the Vdd of the master that is provided by the Pickit3 or this will mess with the voltages on the two units causing troubles?
2) Can I use the simulator of MPlab to test that my code works for transfer and then download it to each device separately?

I appreciate anyone who will try to help me understand a little more on this.
Leo
 
Last edited:

ScottWang

Joined Aug 23, 2012
7,397
Could you draw a block diagram to show you what to do and it is more easier to let our helpers have a common pictures to help you.

The block diagram save as 800x600 .gif or .jpg file.
 

Thread Starter

Leo Silver

Joined Apr 27, 2016
46
Hi,

I use the standard board from PICDEM lab. I just connect the PICKIT to my laptop through the USB port and I connect it with the microcontroller on the other side to debug my code and download it to the microcontroller.
As I use PIC16F690 as master and PIC16F88 as slave, for the SPI connection, it will be as described in the datasheets: SDOmaster(which is PIN9)-to-SDIslave (which is PIN7) and SDOslave(PIN8)-to-SDImaster(PIN13). The clock signal SCK of the master (PIN11) will be connected to that of the slave (PIN10) and the SS of the PIC16F690 (PIN8) will be connected to the PIN11 of the PIC16F88.
I am not sure how to configure the different pins but I found that code online
http://www.microchip.com/forums/m713834.aspx
that I am trying to see how it may apply to my board. At the moment I have connectivity issues as the debugger fails to connect to the microcontroller.
However I want to know how I am supposed to program since I have only one debugger. I assume that it is totally perfect if I program first the one and then the other and then make the connection between them to check if everything works. I could test with an oscilloscope or a LED from the SID port that the data are transmitted but at the moment I have more fundamental issues as I can't make the connection. However yesterday I managed to download the classical blinking LED code and make a LED going on and off but today I can't even download this one.Too frustrating!
 

ErnieM

Joined Apr 24, 2011
8,377
You have two PICs in your system. Yes you can and really have to program one then the other, and pick one to run with the PICkit as debugger.

The PICkit has a low current source limit, something like 100mA. That maybe enough to run both devices. Try it and see.
 

spinnaker

Joined Oct 29, 2009
7,830
Hi everyone,

I have the PICDEM Lab development kit of Microchip tools and I would like to control a peripheral (at first another MCU PIC16F88) through the SPI port of the PIC16F690.
I see that there aren't any functions at either xc8 or Hitech compiler to support the SPI module for this microcontroller but I found some people who have worked around building their own protocols that I want to try to adapt to my system.
Are you certain of that? I am pretty sure HiTech peripheral library supports SPI. Also did you check if the PIC16F88 is supported by MCC in XC8?
 

Picbuster

Joined Dec 2, 2013
1,047
Hi everyone,

I have the PICDEM Lab development kit of Microchip tools and I would like to control a peripheral (at first another MCU PIC16F88) through the SPI port of the PIC16F690.
I see that there aren't any functions at either xc8 or Hitech compiler to support the SPI module for this microcontroller but I found some people who have worked around building their own protocols that I want to try to adapt to my system.
As I am just starting with programming a MCU I have two basic questions:
1) I am using the Pickit3 to power, debug and download my code to the microcontroller.
Could I just program first the slave microcontroller then disconnect the Pickit from the slave and connect it to the master, program the master and make the connection for the data transfer? Also, can I just power my slave from the Vdd of the master that is provided by the Pickit3 or this will mess with the voltages on the two units causing troubles?
2) Can I use the simulator of MPlab to test that my code works for transfer and then download it to each device separately?

I appreciate anyone who will try to help me understand a little more on this.
Leo
1) yes but is handy to use your hw power and make pickit passive (fed from your hw. Avoiding pwrproblems (3v3 and 5V when applicable)
Leave slave and master connected during program load.
2) not all but you can find out if all program steps are taken and observe values from variables, stack and memory use.

About spi xc8 not working for all models ( in description is pic16f excluded)
You have to build your own. Here are the basic setting for SPI pic16f690
Picbuster
//Define all SPI Pins
#define SPI_OUT RC7 // pin 9
#define SPI_IN RB4 // pin 13
#define SPI_CLK RB6 // pin 11
#define SPI_CS RC6 // pin 8
#define Clock_sel RC4
//==========================
#ifndef _XTAL_FREQ
#define _XTAL_FREQ 8000000
#endif






//============ SPI int =========================
if (SSPIF)
{
SSPIF=0; // flag off
Spi_rec[Spi_pointer]=SSPBUF;
Spi_pointer++;
if (Spi_pointer > Memsize) { Spi_pointer=0;} // to many chars? ==>> all in de bin.
// handle result in main.
}


//=====================================================================

// part of main


// -------------------spi bus master ------------------
SSPSTAT= 0b01000000;
CKP=0; //0=idle clock state is low
CKE=1; //0=Data transmitted on falling edge of SCK
SMP=1; //1=SPI mode-Input data sampled at end of data output time
SSPM3=0; //FOSC/4
SSPM2=0; //FOSC/4
SSPM1=0; //FOSC/64
SSPM0=1; //FOSC/4 1=/16

SSPEN=1; // enable spi
 

Thread Starter

Leo Silver

Joined Apr 27, 2016
46
Thank you for you answer :) If I had seen it earlier I might have tried it but I moved on to an Arduino UNO which worked straight away as there are functions and examples already online. Nevertheless I am sure someone will be helped by this in the future!
 
Top