 |
 |
View previous topic :: View next topic |
Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 168
|
No SPI clocks |
Posted: Tue Jul 15, 2025 9:58 am |
|
|
Hi Group, thanks for your help on this-
I am using PCWH v5.093 to compile code for a PIC18F86J60. I am posting a small snippet of code below. I am using the hardware SPI1 to talk to two external SPI devices
The problem is that using either of the use_spi setups, results in no clocks being issue when attempting to write to a SPI device. The Data Out looks reasonable, however, but no clock pulses.
If I comment out both spi_setup statements, I can generate clock pulses on the clock pin (PIN_C3), so there's nothing in the hardware blocking the clock pin.
This is probably something very simple, but I just can't see it. Here's the code:
Code: |
#include <18F86J60.h>
#device ADC=10
#FUSES NOWDT //No Watch Dog Timer
#use delay(crystal=25000000)
#use spi (MASTER, DI=PIN_C4, DO= PIN_C5, CLK= PIN_C3, BITS=8, MODE=0)
//#use spi (MASTER, SPI1, BITS=8, MODE=0)
void main()
{
setup_adc_ports(AN0_TO_AN1, VSS_VDD);
setup_adc(ADC_CLOCK_INTERNAL | ADC_TAD_MUL_0);
output_high(PIN_A3);
output_low(PIN_A3);
delay_us(10);
spi_write (0x50);
spi_write(0x00);
spi_write(0xFF);
delay_us(10);
output_high(PIN_A3);
while(TRUE)
{
}
}
|
|
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 19897
|
|
Posted: Thu Jul 17, 2025 5:54 am |
|
|
Key thing. With #use SPI, you have to use spy_xfer, not spi_write.
You are mixing commands from setup_spi, with those from #use SPI.
You should also specify a clock rate. The default is as fast as possible.
If you look in the manual, under #use spi, you will have listed at the
bottom of the page, the commands that work with this. |
|
 |
|
|
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
|