|
|
View previous topic :: View next topic |
Author |
Message |
cookster666
Joined: 28 Oct 2003 Posts: 3
|
16F877 and Honeywell HMR3300 compass over SPI |
Posted: Tue Oct 28, 2003 8:52 am |
|
|
Hello,
I have been trying to connect to a honeywell hmr3300 via SPI. The HMR3300 has the standard SDI, SDO and SCK lines as well as a chip select. The HMR3300 is supposed to control the SCK line with the PIC16f877 controlling the CS and SDI lines. I have the PIC's SDI and SDO connected to the 3300's SDO and SDI respectively. The SCKs are connected together. I have the CS line connected to port D bit 0.
The HMR3300 datasheet states that the SCK idles low with data output after the falling edge of SCK and data being sampled (I would assume on its SDI line) before the rising edge of SCK. When the host controller (my pic) sets CS low the 3330 will send the 's' character and the pic should send a valid command character. Then the HRM will send two bytes representing the command output.
In my code after setting bit D0 to low I use the spi_read() function to read the first byte and send the command. However it just seems to hang at this point. Any ideas? Is this a standard SPI interface and can I use the CCS functions setup_spi() and read_spi() write_spi() to communicate with this device or will I have to write my own functions?
Thanks,
Andrew |
|
|
Ttelmah Guest
|
Re: 16F877 and Honeywell HMR3300 compass over SPI |
Posted: Tue Oct 28, 2003 10:59 am |
|
|
cookster666 wrote: | Hello,
I have been trying to connect to a honeywell hmr3300 via SPI. The HMR3300 has the standard SDI, SDO and SCK lines as well as a chip select. The HMR3300 is supposed to control the SCK line with the PIC16f877 controlling the CS and SDI lines. I have the PIC's SDI and SDO connected to the 3300's SDO and SDI respectively. The SCKs are connected together. I have the CS line connected to port D bit 0.
The HMR3300 datasheet states that the SCK idles low with data output after the falling edge of SCK and data being sampled (I would assume on its SDI line) before the rising edge of SCK. When the host controller (my pic) sets CS low the 3330 will send the 's' character and the pic should send a valid command character. Then the HRM will send two bytes representing the command output.
In my code after setting bit D0 to low I use the spi_read() function to read the first byte and send the command. However it just seems to hang at this point. Any ideas? Is this a standard SPI interface and can I use the CCS functions setup_spi() and read_spi() write_spi() to communicate with this device or will I have to write my own functions?
Thanks,
Andrew |
Obvious questions, are what syntax you have used on 'setup_spi'. From the description (the HRM, controls the clock), the PIC, needs to be set as a slave device. You also need to work out which edge should be used for sampling (probably low to high). You may also have to disable the chip initially, to make it start.
I suspect the problem is the latency between CS being dropped, and the data being sent. You will need to check this on the data sheet, but if the chip starts sending immediately the CS line is dropped, you will need to go 'DIY', and load the SPI data output register, then drop CS, and wait for the received byte. The 'standard' routines, do not put the character into the output buffer till the 'read' is called, so could well miss the first clock. You could use the standard routines (if this is the problem), by enabling a timer interrupt, trigger the standard routine, and then enabling the chip in the timer interrupt. Since the buffer will allready have been loaded, it should then work.
A typical 'DIY' solution might be something like:
#byte SSPBUF = 0x13
#byte SSPCON = 0x14
#byte SSPSTAT = 0x94
#DEFINE READ_SSP() (SSPBUF)
#DEFINE WAIT_FOR_SSP() while((SSPSTAT & 1)==0)
#DEFINE WRITE_SSP(chr) SSPBUF=(chr)
#DEFINE CLEAR_WCOL() SSPCON=SSPCON & 0x3F
#BIT CS=0x8.0
//ensure chip is _disabled_
CS=1;
//setup SPI
setup_spi(spi_slave | ssp_l_to_h);
//Put 'command' byte into output buffer
WRITE_SSP(command);
//Now trigger the chip
CS=0;
WAIT_FOR_SSP();
//Here the data should have arrived
value=READ_SSP();
Best Wishes |
|
|
|
|
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
|