chipKIT® Development Platform

Inspired by Arduino™

Max32 and MPLAB via PICkit3

Created Fri, 21 Sep 2012 22:31:18 +0000 by HopWorks


HopWorks

Fri, 21 Sep 2012 22:31:18 +0000

For all the engineers and scientists here, please forgive me and my lack of knowledge and experience. I am a hobbyist that has become fairly proficient with MPLAB and C18 for 18F family PC devices. So when I saw the Max32, I simply had to have one. But I am very new to PIC32MX devices and trying, struggling to make the transition to writing code for the PIC32MX795F512L in that environment. The MPIDE and Aurdino sketch environment just isn't for me.

I am not going to ask for a hand out. Well maybe, as far as links for information and sample code. But I'm not going to offer a vague "I want to do this" and ask you to write the code for me. I can do that, just tired of shooting blanks into the dark and need something to latch onto.

OK, sorry for the long-winded intro...

All I want to do is open two UART peripherals. One that uses the Max32's serial to USB chip, USART1 I believe, and another to pins 18 and 19 (TX1, RX1) which is USART4 I believe) that talks to a remote PIC device, the 18F24J50. The idea is to be able to use Hyperterminal (and later a C# app I will write) to communicate with the Max32, and then send data to the remote PIC. I was able to do it with a simple sketch using MPIDE, but I'm in the MPLAB environment now, with a PICkit3 via cable to the header on the Max32.

I will dive off the cliff of interrupt driven RX later. I just need to establish USART with both targets, and the rest I can figure out.

I have searched for several days now for sample code for this, and came up empty.

That's it, thank you so much for your time and patience!

Hop


majenko

Fri, 21 Sep 2012 23:00:30 +0000

Here's the bits of the mpide that configure the serial port:

uart->uxBrg.reg  = ((__PIC32_pbClk / 16 / baudRate) - 1);       // calculate actual BAUD generate value.
        uart->uxSta.reg = 0;
        uart->uxMode.reg = (1 << _UARTMODE_ON);                 //enable UART module
        uart->uxSta.reg  = (1 << _UARTSTA_UTXEN) + (1 << _UARTSTA_URXEN);       //enable transmitter and receiver

And this is to send:

void HardwareSerial::write(uint8_t theChar)
{

        while ((uart->uxSta.reg & (1 << _UARTSTA_TMRT)) == 0)   //check the TRMT bit
                {
                //* wait for the transmitter to be clear
                }


        uart->uxTx.reg = theChar;
}

And receive - this is an interrupt on mpide, but the bit of it that gets a character:

ch = uart->uxRx.reg;

I'll leave it up to you to decypher what registers the variables all point to...


HopWorks

Sat, 22 Sep 2012 00:21:38 +0000

I'm on it Majenko, and that is probably what I need to figure it out.

What is throwing me is all the extra stuff about what state the lines are in (high or low), etc. etc. I don't have in front of me what the chip's defaults are. Interrupts thrown when empty, half full, full, etc. I absolutely LOVE all the options for configuration. I just need to set it up to a widely acceptable standard for now. If anything, to test it.