Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ZhuYanzhen1/MM32_CLion into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuYanzhen1 committed Feb 8, 2022
2 parents 39047d3 + 081c35e commit 3b57057
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
41 changes: 18 additions & 23 deletions program/device/adis16470.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,10 @@

#define SPI3_NSS_SET() GPIO_SetBits(GPIOD, GPIO_Pin_7);
#define SPI3_NSS_RESET() GPIO_ResetBits(GPIOD, GPIO_Pin_7);
#define BURST_READ(x) (x) = (short) software_spi3_mode3(0x0000);\
// checksum += (x);

static const unsigned char address[] =
{
0x04, 0x06, //Gyro_X
0x08, 0x0A, //Gyro_Y
0x0C, 0x0E, //Gyro_Z
0x10, 0x12, //Acc_X
0x14, 0x16, //Acc_Y
0x18, 0x1A, //Acc_Z
};
adis16470_t imu;

/*!
\brief The function to read the registers,
Expand Down Expand Up @@ -69,45 +63,46 @@ void adis16470_write_register(unsigned char address_, unsigned char value) {
spi3_readwrite_byte(tx_tmp);
}

unsigned short adis_read_prod_id(void) {
unsigned short prod_id;
unsigned int adis_read_register(unsigned int register_address) {
unsigned short register_num;
SPI3_NSS_RESET();
delayus(1); // CS时序要求tcs>200ns
software_spi3_mode3(0x7200);
software_spi3_mode3(register_address);
SPI3_NSS_SET();
delayus(25);

SPI3_NSS_RESET();
delayus(1); // CS时序要求tcs>200ns
prod_id = software_spi3_mode3(0x7200);
register_num = software_spi3_mode3(register_address);
SPI3_NSS_SET();
return prod_id;
return register_num;
}

#define BURST_READ(x) delayus(1);\
(x) = (short) software_spi3_mode3(0x0000);

// 突发传输模式不需要发寄存器的地址。只需要发0x6800启动突发传输,后续的176个位就是寄存器的值。仔细看手册
void adis_burst_read() {
// 突发读取功能提供了一种读取一批输出数据寄存器的方法,使用连续的比特流,速率高达1MHz(SCLK)。
// 这种方法不需要每个16位段之间的停顿时间(见图3)。
// 如图27所示,通过设置DIN=0x6800来启动这种模式,然后从DOUT中读出序列中的每个寄存器,同时在整个176位的序列中保持CS为低电平。

unsigned int checksum = 0;
SPI3_NSS_RESET()
spi3_readwrite_byte(0x6800);
software_spi3_mode3(0x6800);

// delayus(1); // burst_read 两次读取中间不确定要多久,所以需要dealy吗?应该不需要?
// imu.diag_star = (short) software_spi3_mode3(0x00);
BURST_READ(imu.diag_star)
BURST_READ(imu.x_gyro)
BURST_READ(imu.y_gyro)
BURST_READ(imu.z_gyro)
BURST_READ(imu.x_acll)
BURST_READ(imu.y_acll)
BURST_READ(imu.z_acll)
BURST_READ(imu.temp)
BURST_READ(imu.temp_out)
BURST_READ(imu.data_cntr)
BURST_READ(imu.checknum)
// BURST_READ(imu.checknum)
imu.checknum = (short) software_spi3_mode3(0x0000);

//
//TODO 计算checksum是否正确
//

SPI3_NSS_SET()

}
6 changes: 3 additions & 3 deletions program/device/adis16470.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ typedef volatile struct {
short x_acll;
short y_acll;
short z_acll;
short temp;
short temp_out;
short data_cntr;
short checknum;
} adis16470_t;

extern adis16470_t imu;
//extern adis16470_t imu;

unsigned short adis_read_prod_id(void);
unsigned int adis_read_register(unsigned int register_address);
void adis16470_read_register(const unsigned char *addr_register, unsigned int *rx_point, unsigned char register_num);
void adis16470_write_register(unsigned char addr, unsigned char value);
void adis_burst_read();
Expand Down
8 changes: 6 additions & 2 deletions program/proc_mcu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ int main(void) {
// printf("printf test.\r\n");
// fflush(stdout);

adis_read_prod_id();
// adis_burst_read();
// unsigned int X = adis_read_register(0x1200);
// unsigned int Y = adis_read_register(0x1600);
// unsigned int Z = adis_read_register(0x1A00);

adis_burst_read();

LED1_TOGGLE();
delayms(500);
}
Expand Down

0 comments on commit 3b57057

Please sign in to comment.