51 lines
1.1 KiB
C
51 lines
1.1 KiB
C
#include "ch438q.h"
|
|
#include "fsmc.h"
|
|
|
|
const uint8_t offsetadd[] = {
|
|
0x00,
|
|
0x10,
|
|
0x20,
|
|
0x30,
|
|
0x08,
|
|
0x18,
|
|
0x28,
|
|
0x38,
|
|
}; /* 串口号的偏移地址 */
|
|
const uint8_t Interruptnum[] = {
|
|
0x01,
|
|
0x02,
|
|
0x04,
|
|
0x08,
|
|
0x10,
|
|
0x20,
|
|
0x40,
|
|
0x80,
|
|
}; /* SSR寄存器中断号对应值 */
|
|
|
|
void ch438_write_reg(uint8_t addr, uint8_t data, uint8_t size)
|
|
{
|
|
uint32_t *address = (uint32_t *)(0x60000000 + addr);
|
|
HAL_SRAM_Write_8b(&hsram1, address, &data, size);
|
|
}
|
|
|
|
uint8_t ch438_read_reg(uint8_t addr, uint8_t size)
|
|
{
|
|
uint8_t data = 0;
|
|
uint32_t *address = (uint32_t *)(0x60000000 + addr);
|
|
HAL_SRAM_Read_8b(&hsram1, address, &data, size);
|
|
return data;
|
|
}
|
|
|
|
void ch438_test(void)
|
|
{
|
|
uint8_t reg_data[16] = {0};
|
|
reg_data[0] = 0xAA;
|
|
ch438_write_reg(offsetadd[0] | REG_SCR_ADDR, reg_data[0], 1);
|
|
|
|
reg_data[1] = ch438_read_reg(offsetadd[0] | REG_SCR_ADDR, 1);
|
|
|
|
reg_data[2] = ch438_read_reg(offsetadd[0] | REG_IER_ADDR, 1);
|
|
reg_data[3] = ch438_read_reg(offsetadd[0] | REG_IIR_ADDR, 1);
|
|
reg_data[4] = ch438_read_reg(offsetadd[0] | REG_LSR_ADDR, 1);
|
|
}
|