MIDI2VC+ UART loop test
Work on the MIDI2VC+ has been a bit down lately, since I'm studying for my ham radio license! It's seems like a fun hobby, so maybe I'll be building RF-stuff soon...
Anyway, my MIDI2VC submission to the hackaday prize got med a T-shirt, which I think is nice. I'm happy to get anything. I mean, the contest was about electronics connected to the Internet, which my project very much wasn't!
In the MIDI2VC project I've finally gotten the mandatory UART loop test working. This is an important step when working with a new MCU, since a successful test means that the following is working:
- Oscillators are running
- Correct bad rate calculated means that oscillators are running at the frequency we expect them to be running at
- Interrupts are working
- IO's are working
Also, we now have a great output for debug info.
Here's the code:
//PIC24FJ64GB004 UART loop test using interrupts
//http://electev.blogspot.com
/*@ignore@*/
#include <xc.h>
/*@end@*/
_CONFIG1(JTAGEN_OFF & GCP_OFF & GWRP_OFF & FWDTEN_OFF & WINDIS_OFF & ICS_PGx3)
_CONFIG2(IESO_OFF & POSCMOD_NONE & OSCIOFNC_ON & FCKSM_CSDCMD & FNOSC_FRC & PLL96MHZ_OFF)
_CONFIG3(WPFP_WPFP0 & SOSCSEL_IO & WUTSEL_FST & WPDIS_WPDIS & WPCFG_WPCFGDIS & WPEND_WPENDMEM)
_CONFIG4(DSWDTPS_DSWDTPS3 & DSWDTOSC_LPRC & RTCOSC_LPRC & DSBOREN_OFF & DSWDTEN_OFF)
//*** UART1 Receive interrupt function ***
//**************************************** k
void __attribute__((__interrupt__, __auto_psv__)) _U1RXInterrupt(void) {
IFS0bits.U1RXIF = 0; //Reset UART1 Receive interrupt bit
U1TXREG = U1RXREG; //Transmit received character
return;
}
int main() {
TRISA = 0x02; //RA1 as input
AD1PCFG = 0xffff; //No analogue inputs
IFS0 = 0x0000; //Interrupts reset
IEC0 = 0x0800; //Uart recieve interrupt enabled
//Reconfigurable pin setup
__builtin_write_OSCCONL(OSCCON & 0xBF);
RPOR2bits.RP5R = 3; //RP5 as UART1 TX
RPINR18bits.U1RXR = 0x06; //RP6 as UART1 RX
__builtin_write_OSCCONL(OSCCON | 0x40);
U1BRG = 25;//Baud rate set to 9600, U1BRG = (8MHz/2)/(16*9600) - 1
U1MODE = 0x8800; //UART1 enabled in simplex mode
U1STA = 0x8400; //Interrupt when char is transferred to TSR and Transmit enabled
while (1) {
}
return 0;
}
Analogue synth prototype demo
I realized that I don't have a proper demo video of the analogue synth prototype I built, so I made one and here it is:
No comments:
Post a Comment