CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

MCP3462

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

MCP3462
PostPosted: Mon Nov 11, 2019 5:21 am     Reply with quote

Hello everybody,

Has anyone had experience with MCP3462 devices?
I have tried all possible combinations and verified registers content but ADC result is always 0.

I know this is not the place for this question but it is a cry for help Rolling Eyes
_________________
George.


Last edited by georpo on Mon Nov 11, 2019 6:06 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Nov 11, 2019 5:43 am     Reply with quote

You should post your test code. As an SPI device, you need the correct 'mode',speed, etc. althought you say you can access registers.

Maybe something 'silly'...

I don't have one to test but.. have you confirmed with a DVM that there IS a positive voltage AT the input terminal of the device ? It could be that pin is grounded, maybe by a solder whisker.

No amount of code will fix a grounded input pin
Jay Sad
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Mon Nov 11, 2019 5:56 am     Reply with quote

Hi temtronic.
Thanks for taking the time to reply.

There is no soldering problem, already tried 2 ICs resoldered them and I am very good at it.

There is voltage at the input.
I also tried the internal temperature sensor with the same 0 output.

I also found another guy having the same problem:


[url]
https://www.microchip.com/forums/m1103547.aspx#1103547
[/url]
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Mon Nov 11, 2019 7:24 am     Reply with quote

As Temtronic says, post some code. The unit can use SPI mode 0, or 3. Assuming you are running at 3.3v, any speed available on a normal PIC.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 1:46 am     Reply with quote

Hello!
Here is the code.



Code:



void FullReset(){
   Select(EXTADC);
    spi_read(0b01111000);         //full reset
   Select(NONE);
   delay_ms(1);
}



void WriteConfiguration(){
   Select(EXTADC);
    spi_read(0b01000110);         //Incremental write starting at 0x01 config0
   spi_read(0b11100011);         //Config0 Internall clock without output,Conversion mode
   spi_read(0b01001100);         //Config1 MCLK/2
   spi_read(0b10001011);         //Config2
   spi_read(0b11110000);         //Config3
   spi_read(0b01110011);         //IRQ
   spi_read(0b00101000);         //MUX select channel 2
   spi_read(0b00000000);         //SCAN MSB
   spi_read(0b00010000);         //SCAN
   spi_read(0b00001111);         //SCAN LSB
   spi_read(0x00);               //TIMER
   spi_read(0x00);               //TIMER
   spi_read(0x00);               //TIMER
   Select(NONE);
}


uint8_t ReadIRQ(){
   uint8_t IR=0;

   Select(EXTADC);
    spi_read(0b01010101);         //read IRQ
   IR=spi_read(0xFF);
   Select(NONE);

   return IR;
}


void ReadADC16b(){

   uint8_t A=0,B=0,C=0,D=0;

   Select(EXTADC);
    spi_read(0b01000001);         //Static Read ADCDATA register
   A=spi_read(0xFF);
   B=spi_read(0xFF);
   C=spi_read(0xFF);
   D=spi_read(0xFF);
   Select(NONE);

   printf(TX232,"%u,%u,%u,%u\n\r",A,B,C,D);

}






Code:


void PIC_init(){      

   TRISA=0b0000000011000001;       
   TRISB=0b0100011000001000;      
   
    LATA=0;
    LATB=0;   

   RPOR6    =0x0700;      // RP13=SDO SPI data output
   RPOR5    =0x0800;      // RP11=SCK SPI clock output
   RPINR20  =10;         // RP10=SDI SPI data input

   RPOR3    =0x0300;      // RP7=U1TX

   CNPU1=0b0001000100000000;

   U1BRG=((32000000/2)/(4*115200))-1;   
   U1MODE=0b1000100000001000;    //
   U1STA =0b0000010100010000; 

    setup_spi(SPI_MASTER | SPI_SCK_IDLE_LOW | SPI_XMIT_L_TO_H | SPI_CLK_DIV_4 | SPI_SS_DISABLED);

   
}


void Main(){   
   uint16_t p=0;

   PIC_init();   

   Select(NONE);   

   printf(TX232,"\fHello.\n\r");   


   FullReset();
   delay_ms(100);
   WriteConfiguration();
   delay_ms(100);

   while(1){

    while(ReadIRQ()&0x40) delay_ms(1);
    ReadADC16b();
    delay_ms(100);
   }
}

_________________
George.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 2:31 am     Reply with quote

For anyone in my case,

Pin /IRQ needs to be configured as "The inactive state is logic High" or use a pull up even if you do not use it!

Wasted 2 days of my life.

Evil or Very Mad
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 2:46 am     Reply with quote

We have all been there....

One comment:

SPI_SS_DISABLED

Not wanted. It probably won't be doing any harm, but this command is for
a _slave_ chip only. Not for a master. I'd have to check what bits it actually
sets.

Second comment. Your writing to RPOR won't work. You cannot write to
these registers without performing an UNLOCK sequence first. Your writes
will be being ignored.
This is what #PIN_SELECT does for you. Generates the unlock sequence, sets
RPOR, and then re-locks the peripheral.
Read the sticky at the top of the forum on how to use PIN_SELECT.
If it is working, it is because the default values in the registers just
happen to match what you want.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 3:45 am     Reply with quote

Dear Ttelmah,

About the SPI_SS_DISABLED, yes I know what it does.
Never used it in the past. This is the first time.
I have to tell you that the waveshare epaper 1.54" does not work if I do not put SPI_SS_DISABLED. I do not know why.
I compared the waveforms in the oscilloscope with and without SPI_SS_DISABLED, they are the same...

About the RPOR and RPINR of course it works. I never used CCS functions for setting remmapable peripheral I/O. I can assure you that it works!
Of course you have to define:

Code:
#word RPOR0=getenv("SFR:RPOR0")

_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 4:01 am     Reply with quote

Tell us what PIC.
For 99% (all I thought) of PIC's, the RPOR registers are protected.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 4:18 am     Reply with quote

All Dspic or PIC24 devices I have used up to now.

DSPIC33FJ64GP802 for example.
PIC24FJ48GA002 in the current project.

It is not that case that the defaults just happen to fit what I randomly use.
I have designed several pcbs with these chips and each time the layout is according to the need and routing ease of the design. And by setting RPOR and RPINR I remap the peripherals.

This is the disassembly listing:

Code:

129:                  RPOR6    =0x0700;      // RP13=SDO SPI data output
  1776  207004     mov.w #0x700,0x0008
  1778  883664     mov.w 0x0008,0x06cc
130:                  RPOR5    =0x0800;      // RP11=SCK SPI clock output
  177A  208004     mov.w #0x800,0x0008
  177C  883654     mov.w 0x0008,0x06ca
131:                  RPINR20  =10;         // RP10=SDI SPI data input
  177E  2000A4     mov.w #0xa,0x0008
  1780  883544     mov.w 0x0008,0x06a8
132:               
133:                  RPOR3    =0x0300;      // RP7=U1TX
  1782  203004     mov.w #0x300,0x0008
  1784  883634     mov.w 0x0008,0x06c6


It just passes the values to the register address. Cool
_________________
George.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 5:01 am     Reply with quote

From the data sheet for this chip:
Quote:

10.4.4.1 Control Register Lock
Under normal operation, writes to the RPINRx and
RPORx registers are not allowed. Attempted writes will
appear to execute normally, but the contents of the
registers will remain unchanged. To change these registers,
they must be unlocked in hardware. The register
lock is controlled by the IOLOCK bit (OSCCON<6>).
Setting IOLOCK prevents writes to the control
registers; clearing IOLOCK allows writes.

To set or clear IOLOCK, a specific command sequence
must be executed:
1. Write 46h to OSCCON<7:0>.
2. Write 57h to OSCCON<7:0>.
3. Clear (or set) IOLOCK as a single operation.
Unlike the similar sequence with the oscillator’s LOCK
bit, IOLOCK remains in one state until changed. This
allows all of the Peripheral Pin Selects to be configured
with a single unlock sequence, followed by an update
to all control registers, then locked with a second lock
sequence.


You are getting away with it because IOLOCK wakes up off, and the
CCS code is not setting it. However this is dangerous since it means
peripheral mappings can get accidentally changed. Much better to
have this feature locked. Use the CCS code. It can handle unlocking
and locking correctly.
georpo



Joined: 18 Nov 2008
Posts: 281
Location: Athens, Greece.

View user's profile Send private message

PostPosted: Tue Nov 12, 2019 5:29 am     Reply with quote

I can not see how they can accidentally changed but I will follow your advice.
Thanks for the tip.
_________________
George.
jcc273



Joined: 24 Mar 2023
Posts: 1

View user's profile Send private message

PostPosted: Fri Mar 24, 2023 1:34 pm     Reply with quote

Oh man i could kiss you. I too wasted a couple days writing a linux driver for this part and combing it over and over and over to see what i was possibly missing then found your post, set the IRQ High and boom life was good again!!! Thank you so much for posting the solution back : )
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group