I am looking to get a SPI serial port running on a PIC32 (PIC32MX360F). can anyone point me to some good resources on how to do this so that a newbie can figure it out? I am using the PIC32 starter kit and have a PIC32 breakout board from Digi-Key.
This is the code that I have been using... I found it in the PIC32 family manual.
#include <p32xxxx.h>
int main(void){
int rData;
IEC0CLR=0x03800000; // disable all interrupts
SPI1CON = 0; // Stops and resets the SPI1.
rData=SPI1BUF; // clears the receive buffer
IFS0CLR=0x03800000; // clear any existing event
IPC5CLR=0x1f000000; // clear the priority
IPC5SET=0x0d000000; // Set IPL=3, Subpriority 1
IEC0SET=0x03800000; // Enable RX, TX and Error interrupts
SPI1BRG=207; // use FPB/4 clock frequency
SPI1STATCLR=0x40; // clear the Overflow
SPI1CON=0x8220; // SPI ON, 8 bits transfer, SMP=1, Master mode
// from now on, the device is ready to transmit and receive data
SPI1BUF='A'; // transmit an A character
while(1){
SPI1BUF= 'A'; // transmit an A character
while(i < 10000){i++;}
i = 0;
}
}
How do I set the baudrate? I am guessing it got something to do with SPI1BRG
EDIT:
Thanks to tcrosley I feel that I am getting closer to being able to communicate with my pic32. I changed SPI1BRG to 207. By my calculations this will set the baudrate to around 9600.
Fsck = Fpb/(2(SPIxBRG +1)) = 4MHZ/(2*(207+1))= 9615
I am trying to view the output on the picchip with HyperTerminal. The settings I am using are:
Baud: 9600
Data bits: 8
Parity: None
Stop bits: 1
Flow Control: None
The pins I am using are:
93 - connected to db9 3
95 - connected to db9 2
and db9 5 is connected to the boards ground...
I am now getting an output, which is nice, but unfortunately it is garbage. my output on HyperTerminal comes out as a bunch of hearts :S now I just feel like my pic32 is mocking me