|
|
View previous topic :: View next topic |
Author |
Message |
Sami
Joined: 29 Oct 2014 Posts: 4
|
spi_init not defined |
Posted: Wed Oct 29, 2014 6:36 am |
|
|
Hey guys,
I am trying to use the SPI protocol using the pic16F887 to communicate with the port expander MCP23S17. then I would run this code into Proteus 8. but I am having a strange problem when trying to use "spi_init()". the error that i got is "Function used but not defined: ... spi_init 471 SCR=2705" here is my code, I think I am missing something.
I am new to CCS, any help would be appreciated.
CCS version 5.025
Code: |
#include <main.h>
#include <stdlib.h>
#use spi(MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4, ENABLE=PIN_C2, BAUD=1000000, MODE=0, BITS=8, STREAM=SPI_1, MSB_FIRST)
void main()
{
set_tris_c(0x10);
output_high(PIN_C6);
output_low(PIN_C6); // Reset the port expander
delay_ms(100);
output_high(PIN_C6);
unsigned int32 baud = 0x100000;
spi_init(SPI_1, baud);
while(TRUE)
{
//TODO: User Code
}
} |
|
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
Re: spi_init not defined |
Posted: Wed Oct 29, 2014 8:02 am |
|
|
Sami wrote: | Hey guys,
I am trying to use the SPI protocol using the pic16F887 to communicate with the port expander MCP23S17. then I would run this code into Proteus 8. but I am having a strange problem when trying to use "spi_init()". the error that i got is "Function used but not defined: ... spi_init 471 SCR=2705" here is my code, I think I am missing something.
I am new to CCS, any help would be appreciated.
CCS version 5.025
Code: |
#include <main.h>
#include <stdlib.h>
#use spi(MASTER, CLK=PIN_C3, DI=PIN_C5, DO=PIN_C4, ENABLE=PIN_C2, BAUD=1000000, MODE=0, BITS=8, STREAM=SPI_1, MSB_FIRST)
void main()
{
set_tris_c(0x10);
output_high(PIN_C6);
output_low(PIN_C6); // Reset the port expander
delay_ms(100);
output_high(PIN_C6);
unsigned int32 baud = 0x100000;
spi_init(SPI_1, baud);
while(TRUE)
{
//TODO: User Code
}
} |
|
You need to look at examples of working applications.
Your are missing:
processor type
processor config (fuse) settings,
#use delay(...) specifying the CPU clock speed
You have specified the TRIS setting which is meaningless in the default mode of the compiler. If you want to specify the I/O configuration manually then you need to add the use FAST_IO directive for the port you are using. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1907
|
Re: spi_init not defined |
Posted: Wed Oct 29, 2014 8:36 am |
|
|
Sami wrote: | ...Proteus 8... |
No proteus questions. See the sticky at the top of the page. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Oct 29, 2014 9:14 am |
|
|
It doesn't compile. To fix this thing, you need to do the following:
1. You have the DI and DO pins swapped in the #use spi() statement.
It could only do software SPI with those settings.
2. #use spi() defaults to software SPI unless specifically told to use
hardware. You can fix this by adding FORCE_HW as a parameter, or
by getting rid of the 3 pin definitions and specify SPI1 instead.
3. The baud parameter in spi_init() can't be a variable. It can only be
a constant. CCS will give an error if you use a variable.
This code compiles OK with vs. 5.030:
Code: |
#include <16F886.h>
#fuses INTRC_IO, NOWDT
#use delay(clock=4M)
#include <stdlib.h>
#use spi(MASTER, SPI1, ENABLE=PIN_C2, BAUD=1000000, MODE=0, BITS=8, STREAM=SPI_1, MSB_FIRST)
void main()
{
set_tris_c(0x10);
output_high(PIN_C6);
spi_xfer(0x55);
output_low(PIN_C6); // Reset the port expander
delay_ms(100);
output_high(PIN_C6);
spi_init(SPI_1, 50000);
while(TRUE)
{
//TODO: User Code
}
} |
|
|
|
Sami
Joined: 29 Oct 2014 Posts: 4
|
|
Posted: Wed Oct 29, 2014 2:54 pm |
|
|
Thanks a lot it works, really appreciated. |
|
|
|
|
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
|