Pic 18f4620, SPI programming

Thread Starter

mcdara

Joined Feb 23, 2011
11
Hey,
Im working in this PIC and trying to get my MOSI pins working as I have this connected into MCP2515 chip acting as the Slave. (The moral of my question below is how to slow down the SPI data out MOSI pin)

I have a code developed and I have a output of 5 volts on my CLK, on the oscilloscope I have the EXT Trigger connected to my chip select. But i am not getting a correct data reading from my data out pin, i have changed the binary number and it still give me the same distorted output, which is not interference so it is trying to give me something. I think maybe if i slow down the clock it will work, i can only slow down the whole PIC which is not what i want, anyone know how to slow down just the SPI mode data output?

Il send some code to explain what I have

Rich (BB code):
#include "p18f4620.h"
#include "spi.h"

#pragma config OSC = INTIO67  // Sets the oscillator mode to HS   
#pragma config WDT = OFF        // Turns the watchdog timer off
#pragma config MCLRE = OFF        // Turns low voltage programming off

void configure_pins(void);
unsigned int read_analog_channel(unsigned int n);

int Count;
void main(void)

initSPI();
    Count  = 0;
    while(1)
    {
    LATDbits.LATD1 = 1;
        LATDbits.LATD0 = 0;    

void configure_pins()

    TRISA = 0xFF;
     ADCON1 = 0b00000111;

LATD = 0;

TRISD = 0b11110000;

LATC = 0;

    TRISC = 0b11110000;

}

unsigned int read_analog_channel(unsigned int n)
{
 // Set ADCON0 to specified channel, unset GO/NOTDONE bit, unset ADON bit
 ADCON0 = n << 2;
 // Select A/D acquisition time (NOT DONE YET - JUST DELAYING MANUALLY FOR NOW, SEE BELOW)
 // Select A/D conversion clock (NOT DONE YET - JUST DELAYING MANUALLY FOR NOW, SEE BELOW)
 // Turn on A/D module
 ADCON0bits.ADON = 1;
 // Manual wait acquisition time (should be more than enough)
 for (n=0 ; n<100 ; ++n);
 // Start conversion
 ADCON0bits.GO = 1;
 // Wait for conversion to finish
 while (ADCON0bits.GO);
 // Just return 8 MSBs of left justified sample from ADRESH:ADRESL
 return ADRESH;
}
 
Last edited by a moderator:
Top