|
|
View previous topic :: View next topic |
Author |
Message |
Oliver Lai
Joined: 12 Dec 2003 Posts: 16
|
SPI PIC18F452 with MAX1463 |
Posted: Thu Feb 05, 2004 6:22 pm |
|
|
Hi, I am working with SPI between PIC18F452 and MAX1463, it is 3 wire SPI. The DI and DO are connected in MAX1463. Below is my code, can anybody help me to find why my read data from MAX1463 is only: 00
Code: |
#define MAX1463_CS PIN_B0
#define MAX1463_DO PIN_C4
#define MAX1463_CLK PIN_C3
void write_spi(byte data)
{
byte i;
output_low(MAX1463_CS);
for(i=0; i<8; i++)
{
output_low(MAX1463_CLK);
if(bit_test(data,7)) output_high(MAX1463_DO);
else output_low(MAX1463_DO);
output_high(MAX1463_CLK);
data <<= 1;
}
output_high(MAX1463_CS);
delay_ms(11);
}
BYTE read_spi()
{
byte i, data=0;
output_low(MAX1463_CS);
delay_us(10);
for(i=0; i<8;i++)
{
output_low(MAX1463_CLK);
if(input(MAX1463_DO)) bit_set(data, i);
output_high(MAX1463_CLK);
}
output_high(MAX1463_CS);
return(data);
}
void init_MAX1463() {
output_high(MAX1463_CLK);
output_high(MAX1463_CS);
write_spi(0X19);
}
#include <18F452.h>
#device ICD=TRUE
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(debugger)
#include <input.c>
void main() {
byte dataL, dataH;
unsigned long data;
init_max1463();
do {
write_spi(0x04);
write_spi(0x28);
dataL = read_spi();
dataH = read_spi();
data = ((dataH<<4) | dataL);
printf("Flow rate: %lu\n", data);
printf("%X %X\n", dataL, dataH);
delay_ms(1000);
} while (TRUE);
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Feb 05, 2004 9:28 pm |
|
|
I think this chip is a lot more complicated than your current driver code.
1. The internal modules of the chip are powered-down initially.
This includes the A/D module. You have to write to the Power
Control register to turn on the module.
2. Your read function only reads 8 bits. But apparently, the chip
can only handle 16-bit read operations, according to the diagram
on page 23. The data sheet also says:
Quote: | The entire 16-bit content of the DHR register is read out
through the DO pin by applying 16 successive clock
pulses to SCLK while CS remains low. DHR is clocked
out MSB bit first. |
3. The A/D must be setup properly before use, and this requires
writing to several registers.
4. The method of writing data into the chip is unusual and complicated,
compared to other SPI chips.
Quote: | Each byte of data written into the MAX1463 serial port
contains a 4-bit addresses nibble (IRSA [3:0]) and a 4-
bit data nibble (IRSD [3:0]). The IRS register holds both
the IRSD and IRSA nibbles as follows:
IRS [7:0] = IRSD [3:0], IRSA [3:0]
Four bytes of IRS information must be written into the
serial interface to transfer 16 bits of data through IRSD
into a MAX1463 internal register.
|
I don't think your driver does that.
Unfortunately, Maxim does not provide any sample drivers that I can see.
They don't even really provide much in the way of examples in the data
sheet. You might email their tech support. They may have some
internal code written for an 8051 or something like that. |
|
|
Oliver Guest
|
SPI issue |
Posted: Thu Feb 05, 2004 11:08 pm |
|
|
I have set up MAX1463 to work, want to get data to PIC microcontroller.
write(0x19); // initial 3 wire SPI in max1463
write(0x04); // put port0 to PFAR[3:0]
write(0x28); //put PFAR[3:0] directed port to DHR |
|
|
|
|
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
|