请选择 进入手机版 | 继续访问电脑版

北京中科昊芯科技有限公司

 找回密码
 立即注册

QQ登录

只需一步,快速开始

楼主: 再玩剁手

汇川变频器MD500E迁移到HXS320F28034/035记录贴(长期更新中。。。)

[复制链接]

14

主题

16

回帖

131

积分

注册会员

积分
131
 楼主| 发表于 2023-5-16 13:19:30 | 显示全部楼层
本帖最后由 再玩剁手 于 2023-5-16 13:48 编辑

16.昨天编译通过,其实还有一个地方需要调整。对于sizeof函数来说,TI的返回值和昊芯的返回值有差异。
int16:TI返回1,昊芯返回2
int32:TI返回2,昊芯返回4
因此,对于一些用sizeof函数的返回值作为循环索引的地方,需要进行除2处理。

而对于一些memcpy函数,直接使用常数作为拷贝长度的,需要将常数乘2处理,涉及到的文件有f_interface.c和f_menu.c;而对于用sizeof的返回值作为memcpy函数拷贝长度的,不用修改。

修改完后,编译结果如下:


  1. riscv32-haawking-elf-size --format=berkeley "MD500E_C_1.57_2020_IDE_V2.1.5.elf"
  2.    text           data            bss            dec            hex        filename
  3. 189672             16          14062         203750          31be6        MD500E_C_1.57_2020_IDE_V2.1.5.elf
复制代码


12

主题

11

回帖

220

积分

管理员

积分
220
发表于 2023-5-19 15:51:21 | 显示全部楼层


作为分割线,在迁移F28035的时候,遇到了一些困难,现在将迁移好的工程,迁移到F28034上面。
(F28034CDD)因为在迁移的时候,会注释掉昊芯提供的驱动库中一些模块的初始化,沿用MD500E中的函数,因此在034的工程中,也需要进行处理。
同时,由于F28034和F28035的IIC模块有些调整,需要修改f_eeprom.c中的处理函数,包括InitSetI2ca,RwEeprom,I2cIntDeal,RwI2cBus。
为了避免混淆,F28034和F28035后面将分享不同的工程,而非通过宏来区分。

修改后,可以在数码管上面显示-H-C-,闪烁一段时间后,则会报ERR07的故障。说明已经完成了功能码的初始化操作。

ERR07是恒速过压故障。这可能是因为未接驱动板导致的。
根据手册说明,ERR07有两种原因,过压抑制设定不合适或者是运行过程中存在外力拖动电机运行。


  1. //=====================================================================
  2. //
  3. // 读写I2C数据
  4. //
  5. //=====================================================================
  6. Uint16 RwI2cBus(Uint16 mode)
  7. {
  8.     int16 i;

  9.    // Wait until the STP bit is cleared from any previous master communication.
  10.    // Clearing of this bit by the module is delayed until after the SCD bit is
  11.    // set. If this bit is not checked prior to initiating a new message, the
  12.    // I2C could get confused.
  13.     if (I2caRegs.I2CMDR.bit.STP == 1)
  14.     {
  15.         return I2C_STP_NOT_READY_ERROR;
  16.     }
  17.    
  18. // Check if bus busy
  19.     if ((I2caRegs.I2CSTR.bit.BB == 1) && (I2cMsg.status != I2C_MSG_STATUS_RESTART))
  20.     {
  21.         return I2C_BUS_BUSY_ERROR;
  22.     }

  23. // Setup slave address
  24. #if (EEPROM_TYPE == EEPROM_24LC32)
  25.     I2caRegs.I2CSAR = I2C_SLAVE_ADDR;
  26. #elif 1
  27.     I2caRegs.I2CSAR = (I2C_SLAVE_ADDR | (I2cMsg.highAddr >> 8)) & 0xff;
  28. #endif   

  29.     if (mode == RW_I2C_BUS_WRITE)
  30.     {
  31.         // Setup number of bytes to send
  32.         // buffer + Address
  33. #if (EEPROM_TYPE == EEPROM_24LC32)
  34.         I2caRegs.I2CCNT = I2cMsg.bytes + 2;
  35. #elif 1
  36.         I2caRegs.I2CCNT = I2cMsg.bytes + 1;
  37. #endif

  38.         I2caRegs.I2CDXR = I2cMsg.highAddr; // Setup data to send
  39. #if (EEPROM_TYPE == EEPROM_24LC32)
  40.         I2caRegs.I2CDXR = I2cMsg.lowAddr;
  41. #endif
  42.         for (i = 0; i < I2cMsg.bytes; i++)
  43.         {
  44.             I2caRegs.I2CDXR = I2cMsg.buffer[i];
  45.         }
  46. #ifdef  DSC28034_CDD
  47.        //20211221 H
  48.            I2caRegs.I2CMDR.bit.MST = 1;
  49.            I2caRegs.I2CMDR.bit.TRX = 1;
  50.            I2caRegs.I2CMDR.bit.STT = 1;
  51.            asm volatile (" NOP ");
  52.            I2caRegs.I2CMDR.all = 0x4E20;
  53. #else
  54.         // Send start as master transmitter
  55.         I2caRegs.I2CMDR.all = 0x6E20;   // S.A.D.P
  56. #endif
  57.     }
  58.     else if ((mode == RW_I2C_BUS_READ) && (I2C_MSG_STATUS_RESTART == I2cMsg.status) )
  59.     {
  60.         I2caRegs.I2CCNT = I2cMsg.bytes; // Setup how many bytes to expect
  61. #ifdef  DSC28034_CDD
  62.         //20211221 H
  63.                 I2caRegs.I2CMDR.bit.MST = 1;
  64.                 I2caRegs.I2CMDR.bit.TRX = 0;
  65.                 I2caRegs.I2CMDR.bit.STT = 1;
  66.                 asm volatile (" NOP ");
  67.                 I2caRegs.I2CMDR.all = 0x4C20;                // Send restart as master receiver
  68. #else
  69.         I2caRegs.I2CMDR.all = 0x6C20;   // Send restart as master receiver
  70. #endif

  71.                                         // S.A.D.P
  72.     }
  73.     else                                        // ACK, or start read
  74.     {
  75. #if (EEPROM_TYPE == EEPROM_24LC32)
  76.         I2caRegs.I2CCNT = 2;
  77.         I2caRegs.I2CDXR = I2cMsg.highAddr;
  78.         I2caRegs.I2CDXR = I2cMsg.lowAddr;
  79. #elif 1
  80.         I2caRegs.I2CCNT = 1;
  81.         I2caRegs.I2CDXR = I2cMsg.highAddr;
  82. #endif
  83.         
  84.         I2caRegs.I2CMDR.all = 0x6620;   // Send data to setup EEPROM address
  85.                                         // S.A.D
  86.     }

  87.     return I2C_SUCCESS;
  88. }


  89. //=====================================================================
  90. //
  91. // I2C总线状态处理
  92. //
  93. //=====================================================================
  94. LOCALF void I2cIntDeal(void)
  95. {
  96.     Uint16 IntSource;
  97.         Uint16 IntNack = 0;
  98. // Read interrupt source
  99. #ifdef  DSC28034_CDD
  100.     while(1)
  101.     {
  102.     IntSource = I2caRegs.I2CISRC.all;
  103.             if (IntSource == I2C_NO_ISRC) break;
  104.             else if(IntSource == I2C_NACK_ISRC)
  105.             {
  106.                     IntNack = 1;
  107.             }
  108.             else if (IntSource == I2C_ARDY_ISRC) break;
  109.             else if (IntSource == I2C_SCD_ISRC) break;
  110.     }
  111.     if ( (IntSource == I2C_NO_ISRC) && (IntNack == 0) )    // 没有中断标志,返回
  112.         return;
  113. #else
  114.      IntSource = I2caRegs.I2CISRC.all;

  115.     if (IntSource == I2C_NO_ISRC)   // 没有中断标志,返回
  116.         return;
  117. #endif


  118.     if (IntSource == I2C_SCD_ISRC)   // Interrupt source = stop condition detected
  119.     {
  120.             I2caRegs.I2CSTR.all = I2C_CLR_SCD_BIT;
  121.         if (I2cMsg.status == I2C_MSG_STATUS_WRITE_BUSY)                //写状态完成后,EEPROM会将数据写入内存中,此时进行ADK查询
  122.         {
  123.             Uint16 tmp = 0;

  124.             while (RwI2cBus(RW_I2C_BUS_ACK) != I2C_SUCCESS) // 如果还没有完成,继续查询I2C总线状态
  125.             {
  126.                 // The EEPROM will send back a NACK while it is performing
  127.                 // a write operation. Even though the write communique is
  128.                 // complete at this point, the EEPROM could still be busy
  129.                 // programming the data. Therefore, multiple attempts are
  130.                 // necessary.
  131.                 if (++tmp >= 100)
  132.                     break;
  133.             }
  134.         }
  135.         // If a message receives a NACK during the address setup portion of the
  136.         // EEPROM read, the code further below included in the register access ready
  137.         // interrupt source code will generate a stop condition. After the stop
  138.         // condition is received (here), set the message status to try again.
  139.         // User may want to limit the number of retries before generating an error.
  140.       #ifdef  DSC28034_CDD

  141.       #else
  142.         else if (I2cMsg.status == I2C_MSG_STATUS_SEND_NOSTOP_BUSY) //ACK查询数据发送完成
  143.         {
  144.             I2cMsg.status = I2C_MSG_STATUS_IDLE;
  145.         }
  146.       #endif

  147.         // If completed message was reading EEPROM data, reset msg to inactive state
  148.         // and read data from FIFO.
  149.         else if (I2cMsg.status == I2C_MSG_STATUS_READ_BUSY)                        //数据读取完成
  150.         {
  151.             int16 i;
  152. //            DELAY_US(1);
  153.             asm volatile (" NOP ");
  154.             for (i = 0; i < I2cMsg.bytes; i++)
  155.             {
  156.                 I2cMsg.buffer[i] = I2caRegs.I2CDRR;
  157.             }
  158.             asm volatile (" NOP ");
  159.             I2cMsg.status = I2C_MSG_STATUS_RW_OK;
  160.         }
  161.     }  // end of stop condition detected
  162.     // Interrupt source = Register Access Ready
  163.     // This interrupt is used to determine when the EEPROM address setup portion of the
  164.     // read data communication is complete. Since no stop bit is commanded, this flag
  165.     // tells us when the message has been sent instead of the SCD flag. If a NACK is
  166.     // received, clear the NACK bit and command a stop. Otherwise, move on to the read
  167.     // data portion of the communication.
  168. #ifdef  DSC28034_CDD
  169.     else if (IntSource == I2C_ARDY_ISRC)    // ARDY中断的发生条件参考I2CSTR说明!   在STP=0时,内部计数器减到0时置位
  170.     {
  171.                 I2caRegs.I2CSTR.all = I2C_CLR_ARDY_BIT;
  172.                 if (I2cMsg.status == I2C_MSG_STATUS_SEND_NOSTOP_BUSY)//ACK结束后进行读操作
  173.         {
  174.                     DELAY_US(30);                 //20211209
  175.                 I2cMsg.status = I2C_MSG_STATUS_RESTART;
  176.         }
  177.                 else if (I2cMsg.status == I2C_MSG_STATUS_WRITE_BUSY)        //写完成,查询EEPROM在线
  178.         {
  179.             I2cMsg.status = I2C_MSG_STATUS_RW_OK;
  180.                         I2caRegs.I2CMDR.bit.STP = 1;
  181.                         //InitSetI2ca();                                                                                //复位I2C
  182.             //I2caRegs.I2CMDR.all = 0x0000;    // reset I2C
  183.             //I2caRegs.I2CMDR.all = 0x0020;
  184.         }
  185.     }
  186.     //2021.12.24        H
  187.         if(IntNack == 1)
  188.         {
  189.                 I2caRegs.I2CMDR.bit.STP = 1;    // 之后SCD=1,进入SCDINT
  190.                 I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;
  191.                 I2caRegs.I2CFFTX.bit.TXFFRST = 0;
  192.                 asm volatile ("NOP");
  193.                 I2caRegs.I2CFFTX.bit.TXFFRST = 1;
  194.         }
  195. #else
  196.     else if (IntSource == I2C_ARDY_ISRC)    // ARDY中断的发生条件参考I2CSTR说明!
  197.     {
  198.         if (I2caRegs.I2CSTR.bit.NACK == 1)
  199.         {
  200.             I2caRegs.I2CMDR.bit.STP = 1;    // 之后SCD=1,进入SCDINT
  201.             I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;
  202.         }
  203.         else if (I2cMsg.status == I2C_MSG_STATUS_SEND_NOSTOP_BUSY)
  204.         {
  205.             I2cMsg.status = I2C_MSG_STATUS_RESTART;
  206.         }
  207.         else if (I2cMsg.status == I2C_MSG_STATUS_WRITE_BUSY)
  208.         {
  209.             I2cMsg.status = I2C_MSG_STATUS_RW_OK;

  210.             InitSetI2ca();
  211.             //I2caRegs.I2CMDR.all = 0x0000;    // reset I2C
  212.             //I2caRegs.I2CMDR.all = 0x0020;
  213.         }
  214.     }
  215. #endif
  216. }
复制代码

  1. void InitSetI2ca(void)
  2. {
  3.     // Initialize I2C
  4.     I2caRegs.I2CMDR.all = 0x4000;    // reset I2C
  5.     I2caRegs.I2CSAR = 0x50;        // Slave address - EEPROM control code
  6. #if (DSP_CLOCK == 140)      // DSP运行频率140MHz
  7.     I2caRegs.I2CPSC.all = 20;        // Prescaler - need 7-12 Mhz on module clk, I2C module clock = 10MHz
  8.     I2caRegs.I2CCLKL = 55;          // clk低电平设置为 (25+5)*0.1us = 3us
  9.     I2caRegs.I2CCLKH = 55;
  10. #endif

  11. #if (DSP_CLOCK == 120)      // DSP运行频率120MHz
  12.     I2caRegs.I2CPSC.all = 11;        // Prescaler - need 7-12 Mhz on module clk, I2C module clock = 10MHz
  13.     I2caRegs.I2CCLKL = 55;          // clk低电平设置为 (25+5)*0.1us = 3us
  14.     I2caRegs.I2CCLKH = 55;
  15. #endif
  16. #if (DSP_CLOCK == 100)      // DSP运行频率100MHz
  17.     I2caRegs.I2CPSC.all = 9;        // Prescaler - need 7-12 Mhz on module clk, I2C module clock = 10MHz
  18.     I2caRegs.I2CCLKL = 55;          // clk低电平设置为 (25+5)*0.1us = 3us
  19.     I2caRegs.I2CCLKH = 55;
  20. #endif
  21. #if (DSP_CLOCK == 80)      // DSP运行频率60MHz
  22.     I2caRegs.I2CPSC.all = 7;        // Prescaler - need 7-12 Mhz on module clk, I2C module clock = 10MHz
  23.     I2caRegs.I2CCLKL = 55;          // NOTE: must be non zero, clk低电平设置为 (55+5)*0.1us = 6us
  24.     I2caRegs.I2CCLKH = 55;          // NOTE: must be non zero, clk高电平设置为 (55+5)*0.1us = 6us
  25. #endif

  26. #if (DSP_CLOCK == 60)      // DSP运行频率60MHz
  27.     I2caRegs.I2CPSC.all = 5;        // Prescaler - need 7-12 Mhz on module clk, I2C module clock = 10MHz
  28.     I2caRegs.I2CCLKL = 25;          // NOTE: must be non zero, clk低电平设置为 (55+5)*0.1us = 6us
  29.     I2caRegs.I2CCLKH = 25;          // NOTE: must be non zero, clk高电平设置为 (55+5)*0.1us = 6us
  30. #endif

  31. #if 0
  32.     I2caRegs.I2CCLKL = 55;          // NOTE: must be non zero, clk低电平设置为 (55+5)*0.1us = 6us
  33.     I2caRegs.I2CCLKH = 55;          // NOTE: must be non zero, clk高电平设置为 (55+5)*0.1us = 6us
  34. #elif 1
  35. //    I2caRegs.I2CCLKL = 55;          // clk低电平设置为 (25+5)*0.1us = 3us
  36. //    I2caRegs.I2CCLKH = 55;
  37. #elif 1     // 200KHz
  38.     I2caRegs.I2CCLKL = 20;          // clk低电平设置为 (20+5)*0.1us = 2.5us
  39.     I2caRegs.I2CCLKH = 20;
  40. #elif 1
  41.     I2caRegs.I2CCLKL = 10;           // 试验ok
  42.     I2caRegs.I2CCLKH = 10;
  43. #elif 1
  44.     I2caRegs.I2CCLKL = 4;           // 试验ok
  45.     I2caRegs.I2CCLKH = 9;
  46. #endif

  47.     I2caRegs.I2CIER.all = 0x0024;   // SCD & ARDY interrupts

  48.     I2caRegs.I2CMDR.all = 0x4020;   // Take I2C out of reset
  49.                                     // Stop I2C when suspended

  50.     I2caRegs.I2CFFTX.all = 0x6040;  // Enable FIFO mode and TXFIFO
  51.     I2caRegs.I2CFFRX.all = 0x2040;  // Enable RXFIFO, clear RXFFINT,
  52.    // I2caRegs.I2CFFRX.all = 0x2040;  // Enable RXFIFO, clear RXFFINT,
  53. }
复制代码






您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|北京中科昊芯科技有限公司 ( 京ICP备19023330号-3 )

GMT+8, 2024-3-29 04:09 , Processed in 0.152504 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表