Okey, tried out open drain configuration today. I got 5V output, but I encountered some problems I would like to get clarified.
Two of the four outputs I used, D9 and C14 would not go low. I tried both setting them to 1 and 0, but they still was high(5V). The two others acted just as excpected.
I understood from the Reference book and the datasheet for the PIC32 that it's only the outputs capable of being analog that can't be Open drain. This will be the B-register. I used the ports C14, D0, D9 and D10, non of this should be a problem, right?
I switched to some other pins(D8 and D11), and these worked fine. But as the magnetometer still won't respond I guess it has something to do with using the wrong pins or not using them right in the software.
As you can see in the code I attached I'm setting the respective ODC bits to 1, and then controlling the outputs with respective PORT-registers.
Maybe the magnetometer is dead, but wanna make completely sure before ordering another one. Any comments to my choosen pins and/or code is welcome:)
Here are the function that sets up the I/O ports:
- Code: Select all
//Setting up the nescessary ports and the serial port.
//Setting the TRIS-registers
TRISCbits.TRISC4 = 1;
TRISDbits.TRISD8 = 0;
TRISCbits.TRISC13 = 1;
TRISDbits.TRISD0 = 0;
TRISDbits.TRISD11 = 0;
TRISDbits.TRISD10 = 0;
//Making the outputs Open Drain
ODCDbits.ODCD8 = 1;
ODCDbits.ODCD0 = 1;
ODCDbits.ODCD11 = 1;
ODCDbits.ODCD10 = 1;
//Setting the initial state of the I/O. D11 is the SSNOT pin, it's
//low during magnetic reading.
PORTDbits.RD0 = 0;
PORTDbits.RD8 = 0;
PORTDbits.RD11 = 1;
PORTDbits.RD10 = 0;
//Setting up the UART1 for 4800 baud.
U1MODE = 0x8008;
U1STA = 0x400;
U1BRG = 2082;
//Settign up the timer1.
T1CON = 0x8030;
Note: this is from after I changed to the "new" I/O ports.