| View previous topic :: View next topic |
| Author |
Message |
JerryR
Joined: 07 Feb 2008 Posts: 190
|
| No SPI clocks PIC16F18424 |
Posted: Mon Mar 09, 2026 11:04 am |
|
|
Can anyone tell me why this code does not generate clocks on SPI1? No clocks confirmed with logic analyser and o-scope.
PCWH v5.121 uC- 16F18424
Thanks!
| Code: |
#include <16F18424.h>
#use delay(clock=32000000) // 8 MHz internal osc
#fuses RSTOSC_HFINTRC_32MHZ
#use spi(MASTER, BITS=8, MODE=0, BAUD=100000)
#pin_select SCK1 = PIN_C0
#pin_select SDI1 = PIN_C1
//=============================================================================
void main ()
{
int8 value1,value2;
while (1)
{
value1= spi_xfer (0);
value2= spi_xfer (0);
}
}
|
|
|
 |
gaugeguy
Joined: 05 Apr 2011 Posts: 358
|
|
Posted: Mon Mar 09, 2026 12:00 pm |
|
|
General comments:
Put the pin_select before # use spi and add SPI1 into #use spi to force it to use the hardware. |
|
 |
JerryR
Joined: 07 Feb 2008 Posts: 190
|
|
Posted: Mon Mar 09, 2026 12:30 pm |
|
|
| Thanks so much for your consideration. Generating clocks now. |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20051
|
|
Posted: Tue Mar 10, 2026 10:50 am |
|
|
I'm surprised you did not get a warning/error with the pin_select after the
#use. |
|
 |
temtronic
Joined: 01 Jul 2010 Posts: 9627 Location: Greensville,Ontario
|
|
Posted: Tue Mar 10, 2026 1:20 pm |
|
|
| and here, this dinosaur , was focused on the delay vs fuses....... |
|
 |
Ttelmah
Joined: 11 Mar 2010 Posts: 20051
|
|
Posted: Wed Mar 11, 2026 3:10 am |
|
|
It is because he is not specifying the SPI port to use. If you change the
#use_spi to:
#use spi(SPI1, MASTER, BITS=8, MODE=0, BAUD=100000)
It then complains that 'PIN NOT ASSIGNED'.
If you think about it as done, the #use is not saying what pin to use
or what port to use, The syntax checking is missing this.... |
|
 |
|