资源简介
多摩川编码器读取程序,支持多摩川ADM485协议,在STM32F4上实验读取TS5668N21成功。
代码片段和文件信息
#include “nrz.h“
#include “usart.h“
#include “tamagawa_interface.h“
#include
#include
//#include
//#include
//#include “resource_table_empty.h“
#include “tamagawa_interface.h“
/* The FIFO size on the PRU UART is 16 bytes; however we are (arbitrarily)
* only going to send 8 at a time */
#define FIFO_SIZE 16
#define MAX_CHARS 12
//volatile register uint32_t __R30;
//volatile __near struct TamagawaInterface TamagawaInterface __attribute__((
// cregister(“PRU_DMEM_0_1“ near) peripheral));
struct TamagawaInterface ti;
uint8_t tx_size = 0 rx_size = 0;
uint8_t tx[4] rx[12];
uint8_t nrz_rx_cnt = 0;
uint32_t abs_data = 0;
uint8_t encoder_id = 0;
uint8_t crc(uint8_t *s uint8_t len);
int tx_prepare(uint8_t *tx uint8_t *tx_size uint8_t *rx_size);
int rx_parse(uint8_t *p);
void crc_verify(uint8_t *p uint8_t len);
void nrz_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOB ENABLE); //IO口时钟配置
//IO配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //复用模式
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //速度等级
//ADM485 CTL
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOB &GPIO_InitStructure);
ti.version = 0x00000001;
ti.data_id = DATA_ID_0;
//TX_ENABLE;
TX_DISABLE;
#ifdef USART2_USE_DMA
usart2_dma_init(2500000);
#else
usart2_init(2500000);
#endif
//memset(rx 0x6B MAX_CHARS);
}
void nrz_send_byte(uint8_t data)
{
USART_SendData(USART2data);
while (USART_GetFlagStatus(USART2 USART_FLAG_TXE) == RESET);
}
//tx_rx(tx_size rx_size tx rx);
void nrz_tx(uint8_t tx_size uint8_t rx_size uint8_t *tx_buffer uint8_t *rx_buffer)
{
TX_ENABLE;
//ADM485_delay(10);
while(tx_size--)
{
//nrz_send_byte(*tx_buffer++);
USART_SendData(USART2*tx_buffer++);
while (USART_GetFlagStatus(USART2 USART_FLAG_TXE) == RESET);
}
ADM485_delay(80);
TX_DISABLE;
// while(rx_size--)
// {
// while(USART_GetFlagStatus(USART2USART_FLAG_RXNE)==0);
// *rx_buffer++ = USART_ReceiveData(USART2);
// }
}
void nrz_read(uint8_t data_id)
{
ti.data_id = data_id;
nrz_rx_cnt = 0;
tx_prepare(tx &tx_size &rx_size);
nrz_tx(tx_size rx_size tx rx);
rx_parse(rx);
}
uint8_t crc(uint8_t *s uint8_t len)
{
uint8_t crc = 0;
uint8_t val;
int i j;
uint8_t data[12];
strncpy((char *)data (const char *)s len);
for(i = 0; i < len; i++)
for(j = 0; j < 8; j++)
{
val = (data[i] >> 7) ^ (crc >> 7);
crc <<= 1;
data[i] <<= 1;
crc |= val;
}
return crc;
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 176 2017-04-01 09:51 prj_F429_TS5668N21\Drive\Include\delay.h
文件 1193 2018-02-28 19:38 prj_F429_TS5668N21\Drive\Include\led.h
文件 781 2017-08-27 16:46 prj_F429_TS5668N21\Drive\Include\tim.h
文件 1305 2018-08-06 15:35 prj_F429_TS5668N21\Drive\Include\usart.h
文件 6434 2018-08-06 18:04 prj_F429_TS5668N21\Drive\nrz.c
文件 806 2018-08-06 17:54 prj_F429_TS5668N21\Drive\nrz.h
文件 3315 2015-08-17 22:47 prj_F429_TS5668N21\Drive\pru_types.h
文件 2895 2018-08-03 18:01 prj_F429_TS5668N21\Drive\resource_table_empty.h
文件 13265 2015-08-17 22:47 prj_F429_TS5668N21\Drive\rsc_types.h
文件 1038 2017-05-17 17:31 prj_F429_TS5668N21\Drive\Source\delay.c
文件 1756 2018-02-28 19:46 prj_F429_TS5668N21\Drive\Source\led.c
文件 2249 2018-08-03 16:15 prj_F429_TS5668N21\Drive\Source\tim.c
文件 11729 2018-08-06 17:49 prj_F429_TS5668N21\Drive\Source\usart.c
文件 16280 2017-05-30 09:21 prj_F429_TS5668N21\Drive\spi_flash.c
文件 3430 2017-05-30 09:31 prj_F429_TS5668N21\Drive\spi_flash.h
文件 1822 2018-08-06 17:55 prj_F429_TS5668N21\Drive\tamagawa_interface.h
文件 399 2011-04-23 10:24 prj_F429_TS5668N21\keilkilll.bat
文件 6079 2018-03-01 19:47 prj_F429_TS5668N21\MY\divider.c
文件 272 2018-03-01 19:47 prj_F429_TS5668N21\MY\divider.h
文件 237 2018-03-01 19:24 prj_F429_TS5668N21\MY\hardware.h
文件 4024 2018-08-06 18:05 prj_F429_TS5668N21\MY\main.c
文件 1246 2018-03-01 18:24 prj_F429_TS5668N21\MY\params.c
文件 848 2018-03-01 18:16 prj_F429_TS5668N21\MY\params.h
文件 5851 2016-11-09 02:19 prj_F429_TS5668N21\MY\stm32f4xx_conf.h
文件 3785 2018-08-03 20:27 prj_F429_TS5668N21\MY\stm32f4xx_it.c
文件 2224 2016-11-09 02:19 prj_F429_TS5668N21\MY\stm32f4xx_it.h
文件 1911 2018-03-01 19:45 prj_F429_TS5668N21\MY\trigger.c
文件 226 2018-03-01 19:42 prj_F429_TS5668N21\MY\trigger.h
文件 2084 2015-10-27 12:06 prj_F429_TS5668N21\Project\DebugConfig\LED_STM32F429BITx.dbgconf
文件 2084 2015-10-27 12:06 prj_F429_TS5668N21\Project\DebugConfig\Target_1_STM32F429BITx.dbgconf
............此处省略263个文件信息
- 上一篇:学生学籍管理系统——毕业设计论文
- 下一篇:Google Map 遥感影像工具
评论
共有 条评论