Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPI with Pic24 and ADC

Status
Not open for further replies.

ernestmyname

Member level 1
Joined
Nov 19, 2009
Messages
33
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Clemson
Activity points
1,548
I have been trying to get SPI up between my PIC24 and a MCP3550 ADC. I have tried several different things but i can't figure out why I continually get a zero written in all three of the iWord registers. I have Chip Select at RB2, SDI at RB3, and SCK at RB4. Any suggestions?

Datasheet for ADC:
**broken link removed**

The PIC controller I'm using is the PIC24HJ64gp202

Code:
sbit Chip_Select at LATB2_bit;

int main() {
    char Word,Buffer;
    int  iWord1, iWord2, iWord3,i;

    //Unlock_IOLOCK();      //Not sure if I need this
    PPS_Mapping(3, _INPUT, _SDI1);
    PPS_Mapping(4, _OUTPUT, _SCK1OUT);
    //Lock_IOLOCK();        //Not sure if I need this

    TRISB = 0x0008;                //RB3 input for SDI1. RP4 output for SCK1OUT
    Chip_Select = 1;
    delay_ms(250);
     SPI1_Init_Advanced(_SPI_MASTER,_SPI_8_BIT,_SPI_PRESCALE_SEC_8,_SPI_PRESCALE_PRI_64,_SPI_SS_DISABLE,_SPI_DATA_SAMPLE_END,_SPI_CLK_IDLE_HIGH,_SPI_IDLE_2_ACTIVE);

    Chip_Select = 0;
    Chip_Select = 1;
    delay_ms(10);
    
    //Wait for ready_not to equal zero
    while(PORTB.B3 != 0) {
        Chip_Select = 1;
        Chip_Select = 0;
        }

    iWord1 = SPI1_Read(Buffer);
    delay_ms(10);
    iWord2 = SPI1_Read(Buffer);
    delay_ms(10);
    iWord3 = SPI1_Read(Buffer);
    delay_ms(10);

    return 0;
    }

Any help or guidance would be greatly appreciated. I can't figure out what I'm leaving out. I have been stuck on this for several days. Thanks in advance!
 

Wow - I can't believe I left that out - Compiler is MikroC. I am going to look into the analog configuration now.

[edit] I just hooked it all up to an oscilliscope and learned that the 3550 is not giving me anything on the SDO port. I am welcome to suggestions but will post up if I figure out what is holding it out. I also added the line
Code:
    AD1PCFGL = 0xFF;

to ensure that all were configured for digital. I can see that the chip is getting SCK from the uController but the controller is getting a data line that is the same as if it were tied to ground/ :(
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top