CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

No SPI clocks

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
JerryR



Joined: 07 Feb 2008
Posts: 169

View user's profile Send private message

No SPI clocks
PostPosted: Tue Jul 15, 2025 9:58 am     Reply with quote

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: 19898

View user's profile Send private message

PostPosted: Thu Jul 17, 2025 5:54 am     Reply with quote

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.
JerryR



Joined: 07 Feb 2008
Posts: 169

View user's profile Send private message

PostPosted: Thu Jul 17, 2025 7:45 am     Reply with quote

Hello Ttelmah:

Thank you so much for your interest!

Yes, the current version of my code uses the correct method and calls, thanks for your clairification. I see from research you have been kind to mention this to quite a few in the group.

Should have posted this yesterday, but my problem with no clocks was solved. BAD LOGIC ANALYSER PROBE! I actually did have clocks using a scope.

Sorry to have raised the question to the group. Lessons here is don't always trust your equipment.

Best regards!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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