用户工具

站点工具


icore4t_56

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
icore4t_56 [2020/04/01 01:22]
zgf
icore4t_56 [2022/04/01 10:57] (当前版本)
sean
行 2: 行 2:
 |技术支持电话|**0379-69926675-801**||| |技术支持电话|**0379-69926675-801**|||
 |技术支持邮件|Gingko@vip.163.com||| |技术支持邮件|Gingko@vip.163.com|||
-|技术论坛|http://​www.eeschool.org||| 
 ^  版本 ​ ^  日期 ​ ^  作者 ​ ^  修改内容 ​ ^ ^  版本 ​ ^  日期 ​ ^  作者 ​ ^  修改内容 ​ ^
 |  V1.0  |  2020-04-01 ​ |  gingko ​ |  初次建立 ​ |  |  V1.0  |  2020-04-01 ​ |  gingko ​ |  初次建立 ​ | 
行 82: 行 81:
 ==== 二、实验设备及平台 ==== ==== 二、实验设备及平台 ====
  
-  - iCore4T 双核心板。+  - iCore4T 双核心板。[[https://​item.taobao.com/​item.htm?​spm=a1z10.1-c.w137644-251734891.3.5923532fDrMDOe&​id=610595120319|点击购买]]
   - iCore4T 扩展底板。   - iCore4T 扩展底板。
-  - JLINK(或相同功能)仿真器。+  - JLINK(或相同功能)仿真器。[[https://​item.taobao.com/​item.htm?​id=554869837940|点击购买]]
   - Micro USB线缆。   - Micro USB线缆。
   - Keil MDK 开发平台。   - Keil MDK 开发平台。
行 307: 行 306:
    
    
- 实验程序 +==== 实验程序 ​==== 
-1.主函数+ 
 +=== 1.主函数 ​=== 
 + 
 +<code c> 
 +int main(void) 
 +
 +    int i; 
 +    unsigned short int temp[10] = {0}; 
 +  HAL_Init();​ 
 +  SystemClock_Config();​ 
 +    i2c.initialize();​ 
 +    axp152.initialize();​ 
 +    axp152.set_dcdc1(3500);//​[ARM & FPGA BK1/2/6 &​OTHER] 
 +    axp152.set_dcdc2(1200);//​[FPGA INT & PLL D] 
 +    axp152.set_aldo1(2500);//​[FPGA PLL A] 
 +    axp152.set_dcdc4(3300);//​[POWER_OUTPUT] 
 +    axp152.set_dcdc3(3300);//​[FPGA BK4][Adjustable] 
 +    axp152.set_aldo2(3300);//​[FPGA BK3][Adjustable] 
 +    axp152.set_dldo1(3300);//​[FPGA BK7][Adjustable] 
 +    axp152.set_dldo2(3300);//​[FPGA BK5][Adjustable] 
 +    HAL_Delay(100);​ 
 + 
 +  MX_GPIO_Init();​ 
 +  MX_USART1_UART_Init();​ 
 +  MX_ADC1_Init();​ 
 +  MX_ADC3_Init();​ 
 + 
 +    usart1.initialize(115200);​ 
 + 
 +  while (1) 
 +  { 
 +        if(_500ms_flag == 1){ 
 +            _500ms_flag = 0; 
 +            my_adc.read(0);​ 
 +            my_adc.read_mux();​ 
 +            temp[0] = my_adc.value[0] * 6 * 100;  //5V监控 放大100倍 
 +            temp[1] = my_adc.value[5] / 2 * 1000.;//​电流监控,取整 
 +            temp[2] = my_adc.value[7] * 2 * 100;  //​3.3V监控 放大100倍 
 +            temp[3] = my_adc.value[4] * 2 * 100;  //​2.5V监控 放大100倍 
 +            temp[4] = my_adc.value[6] * 100;      //​1.2V监控 放大100倍 
 +            temp[5] = my_adc.value[2] * 2 * 100;  //BK3监控 放大100倍 
 +            temp[6] = my_adc.value[1] * 2 * 100;  //BK4监控 放大100倍 
 +            temp[7] = my_adc.value[3] * 2 * 100;  //BK5监控 放大100倍 
 +            temp[8] = my_adc.value[8] * 2 * 100;  //BK7监控 放大100倍 
 +            temp[9] = lm75.read()*100; ​           //​温度监控 放大100倍 
 +            for(i = 0;i < 10;i ++){ 
 +                hold_reg[2*i + 0] = temp[i] >> 8; 
 +                hold_reg[2*i + 1] = temp[i] & 0xFF; 
 +            } 
 +        } 
 +        if(_100ms_flag == 1){ 
 +            _100ms_flag = 0; 
 +            modbus.process();​ 
 +        } 
 +  } 
 +
 + 
 +</​code>​ 
 +=== 2.Modbus相关函数 === 
 +<code c> 
 +static char process(void) 
 +
 +  unsigned short temp; 
 +  unsigned char receive_buffer_temp[140];​ 
 +  int counter_temp;​ 
 +             
 +  //crc 
 +  if(usart1.counter < 2)return 0; 
 +  counter_temp = usart1.counter;​ 
 +  usart1.counter = 0; 
 + 
 +  memcpy(receive_buffer_temp,​usart1.receive_buffer,​counter_temp);​ 
 +  memset(usart1.receive_buffer,​0,​counter_temp);​ 
 + 
 +  temp = receive_buffer_temp[counter_temp - 1] << 8|receive_buffer_temp[counter_temp - 2]; 
 +  if(crc(receive_buffer_temp,​counter_temp - 2) == temp)mb_rsq_pdu(receive_buffer_temp,​counter_temp);​ 
 + 
 +  return 0; 
 +
 + 
 +static int mb_rsq_pdu(unsigned char *receive_buffer_temp,​int counter_temp) 
 + { 
 +   ​if(receive_buffer_temp[0] == mb_slave_address){ 
 +     ​switch(receive_buffer_temp[1]){ 
 +       case 1: 
 +               ​function_1(receive_buffer_temp);​ 
 +               ​break;​ 
 +       case 2: 
 +               ​function_2(receive_buffer_temp);​ 
 +               ​break;​ 
 +       case 3: 
 +               ​function_3(receive_buffer_temp);​ 
 +               ​break;​ 
 +       case 4: 
 +               ​function_4(receive_buffer_temp);​ 
 +               ​break;​ 
 +       case 5: 
 +               ​function_5(receive_buffer_temp,​counter_temp);​ 
 +               ​break;​ 
 +       case 6: 
 +               ​function_6(receive_buffer_temp,​counter_temp);​ 
 +               ​break;​ 
 +       ​default : 
 +               ​mb_excep_rsq_pdu(receive_buffer_temp,​1);​ 
 +               ​break;​ 
 +     } 
 +  }else if(receive_buffer_temp[0] == 0){ 
 +      broadcast(receive_buffer_temp);​ 
 +    } 
 +  return 0; 
 + } 
 + 
 +static int function_1(unsigned char *receive_buffer_temp) 
 +
 +  int i; 
 +  unsigned short cnt; 
 +  unsigned short coil_num; 
 +  unsigned short start_address;​ 
 +  unsigned short crc_value;​ 
 +  int temp; 
 + 
 +  start_address = (receive_buffer_temp[2] << 8) | receive_buffer_temp[3];​ 
 + 
 +  coil_num = receive_buffer_temp[4] << 8| receive_buffer_temp[5];​ 
 +   
 +  if((start_address + coil_num) > 255){ 
 +    mb_excep_rsq_pdu(receive_buffer_temp,​2);​ 
 +    return 1; 
 +  } 
 + 
 +  receive_buffer_temp[2] = ((coil_num % 8 )? (coil_num / 8 + 1) : (coil_num / 8)); 
 +  cnt = receive_buffer_temp[2] + 5; 
 +  if(coil_num % 8){ 
 +    if(coil_num < 8){ 
 +      for(i = 0;i < coil_num;i ++)temp |= 1 << i; 
 +      receive_buffer_temp[3] = ((coil[start_address / 8]) >> (start_address % 8) | (coil[start_address / 8 + 1]) << (8 - (start_address % 8))) & temp; 
 +    }else { 
 +      for(i = 0;i < receive_buffer_temp[2] - 1;​i++)receive_buffer_temp[3 + i] = (coil[i + start_address / 8]) >> (start_address % 8) | (coil[i + start_address / 8 + 1]) << (8 - (start_address % 8)); 
 +      receive_buffer_temp[3 + i] = (coil[i + start_address / 8] << ((8 - (coil_num % 8 - start_address % 8) % 8)) & 0xff) >> (8 - (coil_num % 8)); 
 +    } 
 +  }else { 
 +      for(i = 0;i < receive_buffer_temp[2];​i++)receive_buffer_temp[3 + i] = (coil[i + start_address / 8]) >> (start_address % 8) | (coil[i + start_address / 8 + 1]) << (8 - (start_address % 8)); 
 +  } 
 + 
 +  crc_value = crc(receive_buffer_temp,​cnt - 2); 
 +  receive_buffer_temp[cnt - 2] = crc_value & 0x00ff; 
 +  receive_buffer_temp[cnt - 1] = (crc_value >> 8) & 0xff; 
 + 
 +  for(i = 0;i < cnt;​i++)usart1.send_byte(receive_buffer_temp[i]);​ 
 + 
 +  return 0; 
 +
 + 
 +static int function_3(unsigned char *receive_buffer_temp) 
 +{   
 +  int i; 
 +  int cnt; 
 +  unsigned short int start_address;​ 
 +  unsigned short int crc_value;​ 
 + 
 +  start_address = (receive_buffer_temp[2] << 8) | receive_buffer_temp[3];​ 
 + 
 +  receive_buffer_temp[2] = receive_buffer_temp[5] * 2; 
 +   
 +  if(receive_buffer_temp[2] > 100){ //​判断最大传输量,防止越界 
 +    mb_excep_rsq_pdu(receive_buffer_temp,​2);​ 
 +    return 1; 
 +  } 
 + 
 +  if((start_address * 2 + receive_buffer_temp[2]) > 512){ 
 +    mb_excep_rsq_pdu(receive_buffer_temp,​2);​ 
 +    return 1; 
 +  } 
 + 
 +  cnt = receive_buffer_temp[2] + 5; 
 +  for(i = 0;i < receive_buffer_temp[2];​i++)receive_buffer_temp[i + 3] = hold_reg[start_address * 2 + i]; 
 + 
 +  crc_value = crc(receive_buffer_temp,​cnt - 2); 
 +  receive_buffer_temp[cnt - 2] = crc_value & 0x00ff; 
 +  receive_buffer_temp[cnt - 1] = (crc_value >> 8) & 0xff; 
 + 
 +  for(i = 0;i < cnt;​i++)usart1.send_byte(receive_buffer_temp[i]);​ 
 + 
 +  return 0; 
 +
 + 
 +static int function_5(unsigned char *receive_buffer_temp,​int counter_temp) 
 +
 +  int i; 
 +  unsigned short start_address;​ 
 + 
 +  start_address = (receive_buffer_temp[2] << 8) | receive_buffer_temp[3];​ 
 + 
 +  if(start_address > 255){ 
 +    mb_excep_rsq_pdu(receive_buffer_temp,​2);​ 
 +    return 1; 
 +  } 
 + 
 +  if((receive_buffer_temp[4] == 0xff) && (receive_buffer_temp[5] == 0x00)){ 
 +     ​coil[(start_address / 8)] |= 1 << start_address % 8; 
 +  }else if((receive_buffer_temp[4] == 0x00) && (receive_buffer_temp[5] == 0x00)){ 
 +     ​coil[(start_address / 8)] &= ~(1 << start_address % 8); 
 +  }else { 
 +     ​mb_excep_rsq_pdu(receive_buffer_temp,​3);​ 
 +  } 
 + 
 +  for(i = 0;i < counter_temp;​i++){ 
 +     ​usart1.send_byte(receive_buffer_temp[i]);​  
 +  } 
 +  return 0; 
 + 
 +</​code>​ 
 +=== 3.74HC4051通道配置 === 
    
 +=== 4.ADC初始化函数 ===
 +
    
- Modbus相关函数 
    
-  +=== 5.ADC读取函数 ​=== 
-  +
-  +
-  +
-  +
-3.74HC4051通道配置 +
-  +
-4.ADC初始化函数 +
-  +
-  +
-5.ADC读取函数+
    
    
  
  
- 实验步骤 +==== 3.实验步骤 ​==== 
- 把仿真器与iCore4T的SWD调试口相连(直接相连或者通过转接器相连); +  ​- ​把仿真器与iCore4T的SWD调试口相连(直接相连或者通过转接器相连); 
- 把iCore4T通过Micro USB线与计算机相连,为iCore4T供电; +  ​- ​把iCore4T通过Micro USB线与计算机相连,为iCore4T供电; 
- 打开 Keil MDK 开发环境,并打开本实验工程; +  ​- ​打开 Keil MDK 开发环境,并打开本实验工程; 
- 烧写程序到 iCore4T 上; +  ​- ​烧写程序到 iCore4T 上; 
- 也可以进入Debug 模式,单步运行或设置断点验证程序逻辑。 +  ​- ​也可以进入Debug 模式,单步运行或设置断点验证程序逻辑。 
- 实验现象 +==== 4.实验现象 ​==== 
-通过Modbus Poll软件获得iCore4T的电源电压和温度信息。+  ​* ​通过Modbus Poll软件获得iCore4T的电源电压和温度信息。
    
  
行 356: 行 560:
  
  
-附录: +==== 附录: ​==== 
-1、 选择相应的位(32 位或 64 位)双击,NEXT→NEXT→Install→NEXT→Finished。 + 
-2、 打开 Modbus Poll,点击 Connectionconnect,输入 SN.txt 中的序列号。+1、选择相应的位(32 位或 64 位)双击,NEXT→NEXT→Install→NEXT→Finished。 
 + 
 +2、打开 Modbus Poll,点击 Connection connect,输入 SN.txt 中的序列号。
    
-3、 按下图进行设置,点击 OK 即可。+3、按下图进行设置,点击 OK 即可。
    
  
  
icore4t_56.1585675335.txt.gz · 最后更改: 2020/04/01 01:22 由 zgf