This is my first time using the MSSP module on a PIC chip, though I've got some intermediate experience using other other modules. Because this is my first attempt, I just wrote a simple test program that outputs 1010... to see with the timing and just make sure it's working correctly.
The 18F4520 is on a custom prototype board called a Boogie Board we made in school. I have a Saleae Logic Analyzer channel 0 and 1 hooked up to the SPI (RC5) and CLK(RC3) pins, respectively, and grounded to the BB's ground. Here's my sample program:
Note: Not sure if I need the while(*SSPSTAT & 0x01); but I get the same output either way. Here I'm just waiting for the buffer full flag bit to clear before sending the next value.
Attached are two Saleae screeshots, one zoomed in and the other zoomed out. The 0xAA output is working correctly based on the clock signal, but the clock looks like it's outputting in bursts. I guess this is where I'm stuck because I wouldn't think that's correct. Is this how SPI works or more likely what am I doing wrong?
The 18F4520 is on a custom prototype board called a Boogie Board we made in school. I have a Saleae Logic Analyzer channel 0 and 1 hooked up to the SPI (RC5) and CLK(RC3) pins, respectively, and grounded to the BB's ground. Here's my sample program:
Rich (BB code):
#include <18F4520.h>
#use delay (clock = 20000000)
#fuses HS, NOWDT, NOLVP
#include "library\registers.h" // register lib file
main(){
*TRISC = 0x00; // SDO, CLK output (ignoring input)
*SSPSTAT &= 0xBF; // transition idle->active
*SSPCON1 &= 0x20; // Idle low, SPI Master, clk = Fosc/4
*SSPCON1 |= 0x20; // Enable
while(1){
*SSPBUF = 0xAA; // output 1010 1010
//while(*SSPSTAT & 0x01);
}
}
Attached are two Saleae screeshots, one zoomed in and the other zoomed out. The 0xAA output is working correctly based on the clock signal, but the clock looks like it's outputting in bursts. I guess this is where I'm stuck because I wouldn't think that's correct. Is this how SPI works or more likely what am I doing wrong?
Attachments
-
95.2 KB Views: 37
-
96.1 KB Views: 35