|
|
View previous topic :: View next topic |
Author |
Message |
robertiko
Joined: 19 Feb 2016 Posts: 2
|
spi for pic12f?? |
Posted: Fri Feb 19, 2016 12:46 am |
|
|
hi i need a example for spi and pic12f
i know that i will use all pins but really i need ir
hola alguien tiene algun ejemplo con pic12f y spi
yo se que se usan todos los pines pero realmente necesito esto |
|
|
robertiko
Joined: 19 Feb 2016 Posts: 2
|
|
Posted: Fri Feb 19, 2016 12:55 am |
|
|
I try so, but gives me errors
Code: | #include <12F683.h>
#device ADC=10
#fuses INTRC_IO,NOWDT,NOPUT,NOPROTECT,NOCPD,NOMCLR
#use delay(clock=4000000)
#define GP0 PIN_A5
#define GP1 PIN_A4
#define GP2 PIN_A3
#define GP3 PIN_A2
#define GP4 PIN_A1
#define GP5 PIN_A0
#use spi(DI=PIN_A2, DO=PIN_A1, CLK=PIN_A3)
void init()
{
set_tris_a( 0b11100001 ); // set GP0 output, all other inputs
setup_comparator( NC_NC_NC_NC ); // disable comparators
setup_adc_ports( NO_ANALOGS ); // disable analog inputs
setup_adc( ADC_OFF ); // disable A2D
}
main()
{
while ( TRUE ) // blink LED
{
spi_write(0x70);
}
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 19, 2016 1:12 am |
|
|
spi_write is only used with PICs that have a hardware SPI module.
Quote: | while ( TRUE ) // blink LED
{
spi_write(0x70);
} |
For your PIC and with #use spi(), you should use spi_xfer() as shown
below. Then it will compile.
Quote: | while ( TRUE ) // blink LED
{
spi_xfer(0x70);
} |
Also, at a minimum, you should add parameters for the number of bits
and the SPI mode. Example:
Quote: | #use spi(DI=PIN_A2, DO=PIN_A1, CLK=PIN_A3, bits=8, mode=0) |
#use spi() defaults to using 32 bits, but I think you only want 8 bits.
You need to specify it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Fri Feb 19, 2016 2:13 am |
|
|
As a further comment, there are two ways of specifying the size to send.
The value used in the #USE statement, gives the _maximum_ that spi_xfer will send as a single transaction. You can specify for it to transfer less in the actual spi_xfer statement (but only if using streams).
Advantage of this is that if you want to send an int32 value, this can be sent with a single command.
So:
Code: |
//using:
#use spi(DI=PIN_A2, DO=PIN_A1, CLK=PIN_A3, mode=0, stream=SPI)
//Then:
spi_xfer(SPI,0x70,8);
//will send just 8 bits
While:
spi_xfer(SPI,0x5555AAAA,32);
//will send 32bits
|
This is 'why' CCS setup the command by default to transfer up to 32bits.
Given the largest variable supported by PCB/PCM/PCH, is 32 bits in size, it allows any standard variable to be sent in a single command. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|