|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 03, 2007 1:35 pm |
|
|
Quote: | #include <18F2680.h>
#fuses HS,WDT,PUT,NOPROTECT,NOLVP,NOMCLR |
You have enabled the WatchDog Timer, but you don't have any lines of
code to call the restart_wdt() function. This is not correct. Change the
fuse to NOWDT.
Quote: |
When i check the datasheet, it says that the CS pin should be pulled low
when I am writing to the MCP3909, but if i look that the asm file that
comes with the refrence design, they are pulling the CS high. |
Not true. They set \CS low to enable it. In their sample driver,
the code to read the SPI is in this routine:
Code: | LowPriorityInterrupts |
They use a BCF instruction to set the chip select pin low, and a BSF
instruction to set it high. You can use output_low(CS) and
output_high(CS) to do the same thing.
Quote: |
#ifdef ADC_MCP3909
; Enable phase A I/O so that next data ready pulse can be seen
bsf MPU_ADC_CSC,A ;Disable phase C I/O by setting its CS* HIGH
bcf MPU_ADC_CSA,A ;and enable phase A I/O by setting its CS* LOW
#endif
|
Your code has the CS control statements in the wrong place.
They need to surround the spi_read() statements with the \CS
statements, as shown below. That's how they do it in the sample code.
Also, your SPI read statements are incorrect. You need to put the
data into a variable, as shown below. Also the SPI read statements
must have a 0 parameter to generate the clock.
Code: |
void readMCP3909()
{
output_low(CS);
data1 = spi_read(0);
data2 = spi_read(0);
data3 = spi_read(0);
data4 = spi_read(0);
output_high(CS);
lcd_gotoxy(1,2);
printf(lcd_putc,"%U:%U",data1,data2);
lcd_gotoxy(1,3);
printf(lcd_putc,"%U:%U",data3,data4);
}
|
Do the same thing for the SPI write statement:
Quote: |
void init_MCP3909() //copied from the MCP3909 ref design
{
output_high(MCP3909_MCLR);
delay_ms(4);
output_low(CS);
spi_write(0b10101100);
output_high(CS);
delay_ms(5);
}
|
Also, I didn't see any place in the sample ASM code where they send
0b10101100 to the MCP3909. I could have missed it, but where did
you see this ? |
|
|
Markdem
Joined: 24 Jun 2005 Posts: 206
|
|
Posted: Mon Dec 03, 2007 3:33 pm |
|
|
Hi PCM, I was thinking i had to make the CS pin low, just was not sure.
In regards to making the CS pin high after i have finnished reading or writing to the MCP3909, why do we need to do this? I am only going to use this one device on the SPI bus. I was thinking i could just leave it low all the time.
In the init code, i need to send spi_write(0b10101100) to enable the serial mode in the MCP3909 and set it up to be able to read the V and I values from it. This is both in the datasheet and in the sample ASM.
I will try the changes tonight and see how i go.
Thanks
Mark |
|
|
aaronik19
Joined: 25 Apr 2011 Posts: 297
|
MCP3909 |
Posted: Wed Jun 08, 2011 9:37 am |
|
|
Dear All,
Do you have an application schematic of the MCP3909 please which I can use to get started with this MCP3909? I am trying to download the datasheet but for some reasons, it can't be opened. Thanks for your feedback. |
|
|
|
|
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
|