#include "main.h"
#include "stm32f7xx_hal.h"
#include "MAX14830.h"
#include "bsp.h"
unsigned char ret[2];
extern SPI_HandleTypeDef hspi1;
void CS0_HIGH(void) {HAL_GPIO_WritePin(GPIOC,CS0_Pin,GPIO_PIN_SET);}
void CS0_LOW(void) {HAL_GPIO_WritePin(GPIOC,CS0_Pin,GPIO_PIN_RESET);}
void CS1_HIGH(void) {HAL_GPIO_WritePin(GPIOA,CS1_Pin,GPIO_PIN_SET);}
void CS1_LOW(void) {HAL_GPIO_WritePin(GPIOA,CS1_Pin,GPIO_PIN_RESET);}
void RST0_HIGH(void) {HAL_GPIO_WritePin(GPIOE,RST0_Pin,GPIO_PIN_SET);}
void RST0_LOW(void) {HAL_GPIO_WritePin(GPIOE,RST0_Pin,GPIO_PIN_RESET);}
void RST1_HIGH(void) {HAL_GPIO_WritePin(GPIOA,RST1_Pin,GPIO_PIN_SET);}
void RST1_LOW(void) {HAL_GPIO_WritePin(GPIOA,RST1_Pin,GPIO_PIN_RESET);}
void SCLK_HIGH(void) {HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_SET);}
void SCLK_LOW(void) {HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,GPIO_PIN_RESET);}
void MOSI_HIGH(void) {HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET);}
void MOSI_LOW(void) {HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET);}
#define MISO() HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6)
void delay(unsigned int t)
{
while(t--);
}
/**
* @brief Write and read a val from max14830(num)
* note: read val after write a reg
* @param num: which max14830
* @arg 0: U1
* @arg 1: U6
* @param reg: write reg 0x80|reg
* @param data
*/
unsigned char SPI_WriteRead(unsigned char num,unsigned char reg,unsigned char data)
{
unsigned char i=0;
if(num) CS1_LOW();
else CS0_LOW();
while((SPI1->SR & 0x02)==0)
{
i++;
if(i>254)
break;
}
// if send buffer is not empty,loop
*( __IO uint8_t *)(&hspi1.Instance->DR) = reg;
i=0;
while((SPI1->SR & 0x01)==0)//if receice buff is empty,loop
{
i++;
if(i>254)
break;
}
ret[0]= *( __IO uint8_t *)(&hspi1.Instance->DR);
i=0;
while((SPI1->SR & 0x01)==1)//if receice buff is not empty,loop
{
i++;
if(i>254)
break;
}
i=0;
while((SPI1->SR & 0x02)==0)
{
i++;
if(i>254)
break;
}
*( __IO uint8_t *)(&hspi1.Instance->DR) = data;
i=0;
while((SPI1->SR & 0x01)==0)
{
i++;
if(i>254)
break;
}
ret[1]= *( __IO uint8_t *)(&hspi1.Instance->DR);
i=0;
while((SPI1->SR & 0x01)==1)
{
i++;
if(i>254)
break;
}
if(num) CS1_HIGH();
else CS0_HIGH();
return ret[1];
}
void MAX14830_Set(unsigned char num,unsigned char port,unsigned int baud,unsigned char debug)
{
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1b|0x80,0x40));//[6] set1 to disable CLK
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1e|0x80,0x88));//no RTS PLLBypass no PLLEn Ex Clock
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1c|0x80,0x01));//DVILSB
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1d|0x80,0x00));//DVIMSB
UART8_Send(SPI_WriteRead(num,(port<<5)|0x09|0x80,0x88));//tx mode1
UART8_Send(SPI_WriteRead(num,(port<<5)|0x0b|0x80,0x03));//8bit length
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1b|0x80,0x2c));//enable CLK, set x4 mode
if(debug)
{
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1b,0x40));//[6] set1 to disable CLK
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1e,0x88));//no RTS PLLBypass no PLLEn Ex Clock
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1c,0x01));//DVILSB
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1d,0x00));//DVIMSB
UART8_Send(SPI_WriteRead(num,(port<<5)|0x09,0x88));//
UART8_Send(SPI_WriteRead(num,(port<<5)|0x0b,0x03));//
UART8_Send(SPI_WriteRead(num,(port<<5)|0x1b,0x23));//enable CLK, set x4 mode
}
}
void MX14830_Init(void)
{
RST0_LOW();
RST1_LOW();
HAL_Delay(1000);
RST0_HIGH();
RST1_HIGH();
CS0_HIGH();
CS1_HIGH();
HAL_Delay(1000);
UART8_Send(SPI_WriteRead(0,0x9f,0xce));
UART8_Send(SPI_WriteRead(1,0x9f,0xce));
UART8_Send(SPI_WriteRead(0,0x25,0xff));
UART8_Send(SPI_WriteRead(1,0x25,0xff));
UART8_Send(SPI_WriteRead(0,0x9f,0xcd));
UART8_Send(SPI_WriteRead(1,0x9f,0xcd));
MAX14830_Set(1,0,256000,1);
MAX14830_Set(1,1,256000,1);
MAX14830_Set(1,2,256000,1);
MAX14830_Set(1,3,256000,1);
MAX14830_Set(0,0,256000,1);
MAX14830_Set(0,1,256000,1);
MAX14830_Set(0,2,256000,1);
MAX14830_Set(0,3,256000,1);
}
void MX14830_Send(unsigned char num,unsigned char port,unsigned char data)
{
SPI_WriteRead(num,port<<5|0x80,data);//[6] set1 to disable CLK
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
MAX14830.zip (2个子文件)
MAX14830.h 373B
MAX14830.c 4KB
共 2 条
- 1
资源评论
- szahui2019-12-08谢谢,可以做为参考
- swjtuhbin4182019-12-18感谢分享资料!
同年纪_
- 粉丝: 312
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功