|
|
View previous topic :: View next topic |
Author |
Message |
ac34856
Joined: 14 Dec 2009 Posts: 33 Location: Wales
|
SPI Clock - how do I force on always ? |
Posted: Thu Dec 17, 2009 8:13 am |
|
|
Hi, can anyone help ?
I'm trying to force the clock on the SPI line from an 18F4620
to be present, I used the code below. So far I cant see a clock
or the SDO data when I do multiple writes.
Can anyone tell me in the general scheme of things where
I am going wrong ?
There is nothing connected to the PIC I just want to see the
data lines toggle with the scope connected before I connect
other H/W.
Also, the INT_SSP routine (for some reason) keeps triggering when
there is nothing connected. I am obviously missing something -
Rob
Code: |
//
// Test routine for SPI clock
//
#include <18F4620.h>
#define SDI PIN_C4
#define SDO PIN_C5
#define SCL PIN_C3
#fuses HS, NOWDT, NOPROTECT, NOLVP, BROWNOUT, STVREN
#use DELAY(CLOCK=20000000)
#use RS232(BAUD=115200, PARITY=N, XMIT=PIN_C0, BITS=8, RESTART_WDT, STREAM=DEBUG)
#use SPI(MASTER, DI=SDI, DO=SDO, CLK=SCL, BAUD=115200, BITS=16, FORCE_HW)
static unsigned width=0;
#INT_SSP
void ssp_handler()
{
disable_interrupts(GLOBAL);
printf("\r\n Interrupt on SPI");
enable_interrupts(GLOBAL);
}
void main ()
{
unsigned count=0;
setup_adc_ports(NO_ANALOGS);
setup_adc_ports(ADC_OFF);
enable_interrupts(INT_SSP);
enable_interrupts(GLOBAL);
setup_spi(SPI_MASTER | SPI_L_TO_H); // | SPI_SS_DISABLED);
while(TRUE)
{
spi_write(0xff);
spi_write(0xff);
spi_write(0xff);
printf("\r\n Outputting SPI Clock ? : (%u retries) ", count);
count++;
output_high(PIN_D0);
delay_ms(100);
output_low(PIN_D0);
delay_ms(50);
}
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 17, 2009 8:34 am |
|
|
According to the compiler manual, #use spi() is not intended to be used with spi_write(). You are using an
undefined combination of two SPI methods. |
|
|
ac34856
Joined: 14 Dec 2009 Posts: 33 Location: Wales
|
|
Posted: Thu Dec 17, 2009 8:57 am |
|
|
I read this also,
so how do I do a write with #use spi
and also how do I read ? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Dec 17, 2009 9:03 am |
|
|
I'm not using it for various reasons, but the manual is clear about spi_xfer(). |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 17, 2009 1:46 pm |
|
|
Your program is too complicated. Make a simple program that will
just put out SPI clock and data. Example:
Code: |
#include <18F4620.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=20000000)
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//===============================
main(void)
{
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_16);
while(1)
{
spi_write(0x55);
delay_us(100);
}
} |
Quote: | #INT_SSP
void ssp_handler()
{
disable_interrupts(GLOBAL); // Not necessary
printf("\r\n Interrupt on SPI");
enable_interrupts(GLOBAL); // Very bad
} |
Don't ever do this. You have never seen us do this on the forum.
Read the forum and the PIC data sheet. Don't enable global interrupts
inside an interrupt service routine. |
|
|
|
|
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
|