Pic 18f4620, SPI programming

Discussion in 'Programmer's Corner' started by mcdara, Mar 10, 2011.

  1. mcdara

    Thread Starter New Member

    Feb 23, 2011
    11
    0
    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

    Code ( (Unknown Language)):
    1.  
    2. #include "p18f4620.h"
    3. #include "spi.h"
    4.  
    5. #pragma config OSC = INTIO67  // Sets the oscillator mode to HS  
    6. #pragma config WDT = OFF        // Turns the watchdog timer off
    7. #pragma config MCLRE = OFF        // Turns low voltage programming off
    8.  
    9. void configure_pins(void);
    10. unsigned int read_analog_channel(unsigned int n);
    11.  
    12. int Count;
    13. void main(void)
    14.  
    15. initSPI();
    16.     Count  = 0;
    17.     while(1)
    18.     {
    19.     LATDbits.LATD1 = 1;
    20.         LATDbits.LATD0 = 0;    
    21.  
    22. void configure_pins()
    23.  
    24.     TRISA = 0xFF;
    25.      ADCON1 = 0b00000111;
    26.  
    27. LATD = 0;
    28.  
    29. TRISD = 0b11110000;
    30.  
    31. LATC = 0;
    32.  
    33.     TRISC = 0b11110000;
    34.  
    35. }
    36.  
    37. unsigned int read_analog_channel(unsigned int n)
    38. {
    39.  // Set ADCON0 to specified channel, unset GO/NOTDONE bit, unset ADON bit
    40.  ADCON0 = n << 2;
    41.  // Select A/D acquisition time (NOT DONE YET - JUST DELAYING MANUALLY FOR NOW, SEE BELOW)
    42.  // Select A/D conversion clock (NOT DONE YET - JUST DELAYING MANUALLY FOR NOW, SEE BELOW)
    43.  // Turn on A/D module
    44.  ADCON0bits.ADON = 1;
    45.  // Manual wait acquisition time (should be more than enough)
    46.  for (n=0 ; n<100 ; ++n);
    47.  // Start conversion
    48.  ADCON0bits.GO = 1;
    49.  // Wait for conversion to finish
    50.  while (ADCON0bits.GO);
    51.  // Just return 8 MSBs of left justified sample from ADRESH:ADRESL
    52.  return ADRESH;
    53. }
    54.  
    55.  
     
    Last edited by a moderator: Mar 11, 2011
Loading...