![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
m4k
Joined: 27 Mar 2018 Posts: 29
|
crm200 gyro sensor spi |
Posted: Sun Jan 17, 2021 5:20 am |
|
|
hi..i work on gyro sensor crm200 ...its support spi and analog mode (adc). I can run analog mode and its work properly but in spi mode i have problem...
silicon sensing company Presentation a sample source for spi mode....
but I do not understand how to write and read data..appear this sensor have not any spi address or register map address.
Code: |
/*NOTE: This code was generated for the ATMEL ATMega164 microprocessor. */
/* This is provided as an aid to customers develop their own interface */
/* for the PinPoint gyro. */
/* Setup registers and I/O pins are specific to that processor and will */
/* need to be modified to match those of the processor to be used. */
/*
***********************************************************************************
* COPYRIGHT : Silicon Sensing Systems, 2010 *
* SECURITY CLASSIFICATION : Unrestricted *
* PROJECT NAME : *
* PART NUMBER : *
* FILE NAME : SPI_Port.c *
***********************************************************************************
* DESCRIPTION *
* Functions to run SPI comms ports. *
* *
* *
***********************************************************************************
* CHANGE INFORMATION *
* *
* VER Date Changed By Change.Ref DESCRIPTION *
* === ==== ========== ========== =========== *
* *
* *
***********************************************************************************
*/
#include <inavr.h>
#include <iom164.h>
#include "defines.h"
/* Data types */
typedef unsigned char uint8;
typedef signed char int8;
typedef unsigned int uint16;
typedef signed int int16;
typedef unsigned long uint32;
typedef signed long int32;
/* Large buffer to save message data. This should be in the global */
/* define so that it can be used where SPI_Tx_Buffer and SPI_Rx_Buffer */
/* are actually declared */
#define BUFFER_SIZE 27
/*---------*/
/* Globals */
/*---------*/
extern uint8 SPI_Tx_Buffer[BUFFER_SIZE];
extern uint8 SPI_Rx_Buffer[BUFFER_SIZE];
/*--------------------------*/
/* Initialise_SPI_As_Master */
/*--------------------------*/
void Initialise_SPI_As_Master(uint8 SPI_Speed)
{
/* Set data direction register for port B (SPI port) to make */
/* SCK an output PB7 */
/* MISO an input PB6 */
/* MOSI an output PB5 */
/* SS an output PB4 */
/* The register initialises to all 0 so everything else is an input, yes I know | 0<< */
/* does nothing but it makes the point as this bit should be 0. */
DDRB = DDRB | (1<<DDB7) | (0<<DDB6) | (1<<DDB5) | (1<<DDB4);
/* Drive the SS line high to stop any chance of the SPI port being deselected */
PORTB = PORTB | (1<<PB4);
/* Reset the SPCR register */
SPCR = 0;
/* Reset the SPSR register */
SPSR = 0;
/* Enable SPI */
/* Set SPI Master mode */
/* Set Data order as MSB first */
/* Set SPI mode 0 i.e. CPOL and CPHA = 0in Master mode */
SPCR = SPCR | (1<<SPE0) | (1<<MSTR0);
/* Set SPI clock speed to 1.25MHZ:
/* Set clock to be fck/16 */
/* This should give a SPI bus clock of 20MHz/16 = 1.25MHz */
SPCR = SPCR | (0<<SPR01) | (1<<SPR00);
SPSR = SPSR | (0<<SPI2X0);
}
/*-----------------------------------*/
/* Transfer_1_Message_Using_SPI_Port */
/*-----------------------------------*/
void Transfer_1_Message_Using_SPI_Port(uint8 Number_Of_Bytes)
{
int i;
/* Set SS line low */
Set_SS_Line_Low();
/* Add delay to allow device to action SS line going low */
/* For PinPoint this needs to be 25uS */
Timer_2_Delay_25uS();
for(i=0; i<Number_Of_Bytes; i++)
{
/* Get a byte from the buffer and place it in the SPI output register */
SPDR = SPI_Tx_Buffer[i];
/* Wait for the data to be sent */
while( (SPSR & (1<<SPIF0)) != (1<<SPIF0) );
/* Copy the received byte into the buffer */
SPI_Rx_Buffer[i] = SPDR;
}
/* Add 5uS delay for PinPoint */
Timer_2_Delay_5uS();
/* Set SS line high */
Set_SS_Line_High();
}
|
https://www.siliconsensing.com/media/1160/crm200-00-0100-132_rev_9.pdf
in spi mode for this chip No address? or register address? how to read register map or single gyro data? can i use one spi bus for this sensor and other sensor that support spi mode?
thanks alot |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sun Jan 17, 2021 6:56 am |
|
|
here's your main problem....
from the code presented...
This code was generated for the ATMEL ATMega164 microprocessor.
Historically , SPI devices do not have 'chip' or 'device' addresses, rather they use a 'chip select' pin to control what device the micro communicates with.
Yes, there will be 'registers' within the device,those are used for setting up the actual device |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19359
|
|
Posted: Sun Jan 17, 2021 7:56 am |
|
|
The key is this line:
for(i=0; i<Number_Of_Bytes; i++)
The chip returns 6 bytes. You simply drop the select, wait a moment
for it to be ready, then read six bytes. Then raise the select.
Look at 7.12.1 in the data sheet.
Note then the two timing limitations. 25uSec between CS and reading
the first byte, and 5uSec after reading the last byte before raising CS.
The master sends a message at the same time as receiving the reply.
The transmitted message is a 'command' messages. The answer is
a 'status' message. Look at
figure 7.7, and 7.8. The message is always 6 bytes, though as you see
for the 'command' message, there are actually 4 bytes doing nothing.
The status message is always a single byte indicating the status of the
sensor, followed by two bytes giving the current 'rate' data, then two
bytes giving the temperature, and finally a checksum.
You start by sending a command message to setup the chip, then send
this again, now getting the reply for this setup. Your message needs to
have the checksum correct or it won't be accepted by the chip.
Repeat rate typically 1KHz (10KHz max), with an SPI clock rate
recommended to be 1MHz.
There is only one setup register, set by the command byte, and you
get back 5 bytes (and checksum). |
|
![](templates/subSilver/images/spacer.gif) |
m4k
Joined: 27 Mar 2018 Posts: 29
|
|
Posted: Sun Jan 17, 2021 10:03 am |
|
|
Ttelmah wrote: | The key is this line:
for(i=0; i<Number_Of_Bytes; i++)
The chip returns 6 bytes. You simply drop the select, wait a moment
for it to be ready, then read six bytes. Then raise the select.
Look at 7.12.1 in the data sheet.
Note then the two timing limitations. 25uSec between CS and reading
the first byte, and 5uSec after reading the last byte before raising CS.
The master sends a message at the same time as receiving the reply.
The transmitted message is a 'command' messages. The answer is
a 'status' message. Look at
figure 7.7, and 7.8. The message is always 6 bytes, though as you see
for the 'command' message, there are actually 4 bytes doing nothing.
The status message is always a single byte indicating the status of the
sensor, followed by two bytes giving the current 'rate' data, then two
bytes giving the temperature, and finally a checksum.
You start by sending a command message to setup the chip, then send
this again, now getting the reply for this setup. Your message needs to
have the checksum correct or it won't be accepted by the chip.
Repeat rate typically 1KHz (10KHz max), with an SPI clock rate
recommended to be 1MHz.
There is only one setup register, set by the command byte, and you
get back 5 bytes (and checksum). |
thank you |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|