[活动] 【开发板评测】像玩Arduino一样玩LaunchPad MSP430G2开发板

[复制链接]
1261|2
 楼主| gaoyang9992006 发表于 2020-3-1 10:49 | 显示全部楼层 |阅读模式
本帖最后由 gaoyang9992006 于 2020-3-1 10:50 编辑

近期因为疫情,一直关在家里,找到了几块好多年前在21ic.com参加活动弄的板子。其中就有我的第一块论坛获取的开发板MSP430G2的LaunchPad开发板。
之前才用CCStudio开发,需要熟悉很多寄存器的配置。最近我看到其实可以用MSP430版本的Arduino,也就是energia。下载这个软件超级难的。废了两天时间终于下载到最新版了,经过测试发现该版本的energia,可以正常编译,却无法上传,我不知道如何修复这个问题,搜索了一下,有一些国外网友发帖咨询过,但是没有人给出答案,这也许要深入研究Arduino的上传功能才行。然后我加了很多430的群,终于打探到了上一个版本。经过测试上一个版本energia-1.8.7E21可以正常上传,但是编译后的文件时间系统是错误的,比正常的定时慢了十几倍,也就是说,如果我在程序中定时1S,实际运行确实十几秒。经过研究,复制时间的代码在core里面,然后我从最新版的core里面复制过去,覆盖了energia-1.8.7E21版本的core代码文件。终于修复出来了一个可以正常编译,正常上传的energia开发软件了。
修复后的energia-1.8.7E21下载地址:https://bbs.21ic.com/icview-2925598-1-1.html
默认的该软件具备了MSP430各个版本的LaunchPad开发功能。而其他的LaunchPad需要在线安装支持文件,但是因为国内网络的问题,你很难联系到外网进行更新。所以这里我只能体验430的开发板了。刚好我手里有的就是MSP-EXP430G2的LaunchPad开发板。

我手里的是1.5版本。
据官网介绍,MSP430G2 LaunchPad套件有一个新版本– MSP-EXP430G2ET,其中包括改进的EnergyTrace测量以及用于编程和调试的板上仿真。不过管脚都是完全兼容的,因为用的MCU还是2553或2452(说明:该开发板提供了两个MCU,可以替换)。该开发板的用户指南
MSP430G2452的片上配置: 16 位超低功耗微控制器,  8kB 闪存、256B RAM、10 位 SAR A/D、比较器、用于 SPI/I2C 的 USI、16 个触控式使能 I/O 引脚。
MSP430G2533的片上配置:16 位超低功耗微控制器,16kB 闪存、512B RAM、10 位 SAR A/D、比较器、用于 I2C/SPI/UART 的USCI、24 个触控式使能 I/O 引脚
可以看出2533比2452在闪存和内存的配置上都比2452高一倍。
接下来就体验energia的开发模式。
1,用mini-USB连接线,连接开发板与电脑USB接口,打开Energia开发软件,如下图所示。


单击工具菜单,选择你的开发板配置的MCU

如上图所示,选择你板子上此时安装的MCU型号。然后再选择端口为你开发板的串口号。
接下来就是跑一个例子试试了,最简单的点灯(Blink):文件—>示例—>01.Basics—>Blink.
如下图所示。


接下来就是编译运行了,如下图所示的五个按钮分别是:验证,上传,新建,打开,保存。其中验证就是编译源文件。上传就是烧写固件到芯片。因此我们需要先按验证(第一个按钮),完成后再按第二个按钮

接下来见证奇迹的时刻到了


  1. 项目使用了 802 字节,占用了 (9%) 程序存储空间。最大为 8192 字节。
  2. 全局变量使用了20字节,(7%)的动态内存,余留236字节局部变量。最大为256字节。
  3. MSPDebug version 0.24 - debugging tool for MSP430 MCUs
  4. Copyright (C) 2009-2016 Daniel Beer <dlbeer@gmail.com>
  5. This is free software; see the source for copying conditions.  There is NO
  6. warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  7. ----------------- NOTE ------------------
  8. Modified version of mspdebug for Energia
  9.             Do not use standalone
  10. -----------------------------------------
  11. Chip info database from MSP430.dll v3.3.1.4 Copyright (C) 2013 TI, Inc.

  12. Using new (SLAC460L+) API
  13. MSP430_GetNumberOfUsbIfs
  14. MSP430_GetNameOfUsbIf
  15. Found FET: HID0006:COM3
  16. MSP430_Initialize: HID0006:COM3
  17. Firmware version is 20409001
  18. MSP430_VCC: 3000 mV
  19. MSP430_OpenDevice
  20. MSP430_GetFoundDevice
  21. Device: MSP430G2xx2 (id = 0x00cf)
  22. 2 breakpoints available
  23. MSP430_EEM_Init
  24. Chip ID data:
  25.   ver_id:         5224
  26.   ver_sub_id:     0000
  27.   revision:       00
  28.   fab:            a0
  29.   self:           0000
  30.   config:         00
  31. Device: MSP430G2xx2
  32. Erasing...
  33. Programming...
  34. Writing  770 bytes at e000...
  35. Writing   32 bytes at ffe0...
  36. Done, 802 bytes total
  37. MSP430_Run
  38. MSP430_Close
顺利完成编译。然后板子上的红色灯泡就开始闪闪发光了。
接下来我们修改一下程序,让板子上的绿色灯泡也一闪一闪的。
  1. /*
  2.   Blink
  3.   The basic Energia example.
  4.   Turns on an LED on for one second, then off for one second, repeatedly.
  5.   Change the LED define to blink other LEDs.
  6.   
  7.   Hardware Required:
  8.   * LaunchPad with an LED
  9.   
  10.   This example code is in the public domain.
  11. */

  12. // most launchpads have a red LED
  13. //#define LED RED_LED

  14. //see pins_energia.h for more LED definitions
  15. //#define LED GREEN_LED
  16.   
  17. // the setup routine runs once when you press reset:
  18. void setup()
  19. {               
  20.   // initialize the digital pin as an output.
  21.   pinMode(RED_LED, OUTPUT);
  22.   pinMode(GREEN_LED, OUTPUT);      
  23. }

  24. // the loop routine runs over and over again forever:
  25. void loop()
  26. {
  27.   digitalWrite(RED_LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  28.   digitalWrite(GREEN_LED, LOW);   // turn the LED on (HIGH is the voltage level)

  29.   delay(1000);               // wait for a second
  30.   digitalWrite(RED_LED, LOW);    // turn the LED off by making the voltage LOW
  31.   digitalWrite(GREEN_LED, HIGH);   // turn the LED on (HIGH is the voltage level)  
  32.   delay(1000);               // wait for a second

  33.   
  34. }
这样就可以红绿灯交替点亮了,看起来这才好嘛。




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| gaoyang9992006 发表于 2020-3-1 10:57 | 显示全部楼层
那么如何知道开发板上芯片管脚在Energia中定义的名字呢?打开软件的安装目录,如下所示

energia-1.8.7E21\hardware\energia\msp430\variants\MSP-EXP430G2452LP

例如找到2452定义文件
pins_energia.h
  1. /*
  2.   ************************************************************************
  3.   *   pins_energia.h
  4.   *
  5.   *   Energia core files for MSP430
  6.   *      Copyright (c) 2012 Robert Wessels. All right reserved.
  7.   *
  8.   *     Contribution: Rei VILO
  9.   *
  10.   ***********************************************************************
  11.   Derived from:
  12.   pins_arduino.h - Pin definition functions for Arduino
  13.   Part of Arduino - http://www.arduino.cc/

  14.   Copyright (c) 2007 David A. Mellis

  15.   This library is free software; you can redistribute it and/or
  16.   modify it under the terms of the GNU Lesser General Public
  17.   License as published by the Free Software Foundation; either
  18.   version 2.1 of the License, or (at your option) any later version.

  19.   This library is distributed in the hope that it will be useful,
  20.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  22.   Lesser General Public License for more details.

  23.   You should have received a copy of the GNU Lesser General
  24.   Public License along with this library; if not, write to the
  25.   Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  26.   Boston, MA  02111-1307  USA
  27. */

  28. #ifndef Pins_Energia_h
  29. #define Pins_Energia_h
  30. #ifndef BV
  31. #define BV(x) (1 << (x))
  32. #endif

  33. static const uint8_t SS      = 8;  /* P2.0 */
  34. static const uint8_t SCK     = 7;  /* P1.5 */
  35. static const uint8_t MOSI    = 15; /* P1.7 */
  36. static const uint8_t MISO    = 14; /* P1.6 */
  37. static const uint8_t TWISCL1  = 9;   /* P2.1 SW I2C */
  38. static const uint8_t TWISDA1  = 10;  /* P2.2 SW I2C */
  39. static const uint8_t TWISDA0  = 15;  /* P1.7 */
  40. static const uint8_t TWISCL0  = 14;  /* P1.6 */
  41. static const uint8_t DEBUG_UARTRXD = 3;  /* Receive  Data (RXD) at P1.1 */
  42. static const uint8_t DEBUG_UARTTXD = 4;  /* Transmit Data (TXD) at P1.2 */
  43. #define TWISDA1_SET_MODE  (INPUT)
  44. #define TWISCL1_SET_MODE  (INPUT)
  45. #if defined(__MSP430_HAS_USCI__)
  46. #define TWISDA0_SET_MODE  (PORT_SELECTION0 | PORT_SELECTION1 /* | INPUT_PULLUP*/) /* do not enable the pull ups for this device */
  47. #define TWISCL0_SET_MODE  (PORT_SELECTION0 | PORT_SELECTION1 /* | INPUT_PULLUP*/)
  48. #define DEBUG_UARTRXD_SET_MODE (PORT_SELECTION0 | PORT_SELECTION1 | INPUT)
  49. #define DEBUG_UARTTXD_SET_MODE (PORT_SELECTION0 | PORT_SELECTION1 | OUTPUT)
  50. #define SPISCK_SET_MODE (PORT_SELECTION0 | PORT_SELECTION1)
  51. #define SPIMOSI_SET_MODE (PORT_SELECTION0 | PORT_SELECTION1)
  52. #define SPIMISO_SET_MODE (PORT_SELECTION0 | PORT_SELECTION1)
  53. #endif
  54. #if defined(__MSP430_HAS_USI__)
  55. #define TWISDA0_SET_MODE  (PORT_SELECTION0 | INPUT_PULLUP)
  56. #define TWISCL0_SET_MODE  (PORT_SELECTION0 | INPUT_PULLUP)
  57. #define DEBUG_UARTRXD_SET_MODE (PORT_SELECTION0 | INPUT)
  58. #define DEBUG_UARTTXD_SET_MODE (PORT_SELECTION0 | OUTPUT)
  59. #define SPISCK_SET_MODE (PORT_SELECTION0)
  60. #define SPIMOSI_SET_MODE (PORT_SELECTION0)
  61. #define SPIMISO_SET_MODE (PORT_SELECTION0)
  62. #endif

  63. /* Define the default I2C settings */
  64. #define DEFAULT_I2C -1 /* indicates SW I2C on pseudo module 1 */
  65. #define TWISDA TWISDA1
  66. #define TWISCL TWISCL1
  67. #define TWISDA_SET_MODE  TWISDA1_SET_MODE
  68. #define TWISCL_SET_MODE  TWISCL1_SET_MODE

  69. #define DEBUG_UART_MODULE_OFFSET 0x0

  70. #define DEBUG_UART_MODULE 0x0

  71. static const uint8_t A0  = 2;
  72. static const uint8_t A1  = 3;
  73. static const uint8_t A2  = 4;
  74. static const uint8_t A3  = 5;
  75. static const uint8_t A4  = 6;
  76. static const uint8_t A5  = 7;
  77. static const uint8_t A6  = 14;
  78. static const uint8_t A7  = 15;
  79. static const uint8_t A10 = 128 + 10; // special. This is the internal temp sensor

  80. //                      +-\/-+
  81. //               VCC   1|    |20  GND
  82. //         (A0)  P1.0  2|    |19  XIN
  83. //         (A1)  P1.1  3|    |18  XOUT
  84. //         (A2)  P1.2  4|    |17  TEST
  85. //         (A3)  P1.3  5|    |16  RST#
  86. //         (A4)  P1.4  6|    |15  P1.7  (A7) (SCL) (MISO) depends on chip
  87. //         (A5)  P1.5  7|    |14  P1.6  (A6) (SDA) (MOSI)
  88. //               P2.0  8|    |13  P2.5
  89. //               P2.1  9|    |12  P2.4
  90. //               P2.2 10|    |11  P2.3
  91. //                      +----+
  92. //

  93. // Pin names based on the silkscreen
  94. //
  95. static const uint8_t P1_0 = 2;
  96. static const uint8_t P1_1 = 3;
  97. static const uint8_t P1_2 = 4;
  98. static const uint8_t P1_3 = 5;
  99. static const uint8_t P1_4 = 6;
  100. static const uint8_t P1_5 = 7;
  101. static const uint8_t P2_0 = 8;
  102. static const uint8_t P2_1 = 9;
  103. static const uint8_t P2_2 = 10;
  104. static const uint8_t P2_3 = 11;
  105. static const uint8_t P2_4 = 12;
  106. static const uint8_t P2_5 = 13;
  107. static const uint8_t P1_6 = 14;
  108. static const uint8_t P1_7 = 15;
  109. static const uint8_t P2_7 = 18;
  110. static const uint8_t P2_6 = 19;

  111. static const uint8_t RED_LED = 2;
  112. static const uint8_t GREEN_LED = 14;
  113. static const uint8_t PUSH2 = 5;
  114. static const uint8_t TEMPSENSOR = 128 + 10; // depends on chip


  115. #ifdef ARDUINO_MAIN

  116. const uint16_t port_to_input[] = {
  117.    NOT_A_PORT,
  118.    (const uint16_t) (&P1IN),
  119.    (const uint16_t) (&P2IN),
  120. #ifdef __MSP430_HAS_PORT3_R__
  121.    (const uint16_t) (&P3IN),
  122. #endif
  123. };

  124. const uint16_t port_to_output[] = {
  125.    NOT_A_PORT,
  126.    (const uint16_t) (&P1OUT),
  127.    (const uint16_t) (&P2OUT),
  128. #ifdef __MSP430_HAS_PORT3_R__
  129.    (const uint16_t) (&P3OUT),
  130. #endif
  131. };

  132. const uint16_t port_to_dir[] = {
  133.    NOT_A_PORT,
  134.    (const uint16_t) (&P1DIR),
  135.    (const uint16_t) (&P2DIR),
  136. #ifdef __MSP430_HAS_PORT3_R__
  137.    (const uint16_t) (&P3DIR),
  138. #endif
  139. };

  140. const uint16_t port_to_ren[] = {
  141.    NOT_A_PORT,
  142.    (const uint16_t) (&P1REN),
  143.    (const uint16_t) (&P2REN),
  144. #ifdef __MSP430_HAS_PORT3_R__
  145.    (const uint16_t) (&P3REN),
  146. #endif
  147. };

  148. const uint16_t port_to_sel0[] = {  /* put this PxSEL register under the group of PxSEL0 */
  149.    NOT_A_PORT,
  150.    (const uint16_t) (&P1SEL),
  151.    (const uint16_t) (&P2SEL),
  152. #ifdef __MSP430_HAS_PORT3_R__
  153.    (const uint16_t) (&P3SEL),
  154. #endif
  155. };

  156. const uint16_t port_to_sel2[] = {
  157.    NOT_A_PORT,
  158. #if (defined(P1SEL2_) || defined(P1SEL2) || defined(__MSP430_HAS_P1SEL2__))
  159.    (const uint16_t) (&P1SEL2),
  160. #else
  161.         NOT_A_PORT,
  162. #endif
  163. #if (defined(P2SEL2_) || defined(P2SEL2) || defined(__MSP430_HAS_P2SEL2__))
  164.    (const uint16_t) (&P2SEL2),
  165. #else
  166.         NOT_A_PORT,
  167. #endif
  168. #if (defined(P3SEL2_) || defined(P3SEL2) || defined(__MSP430_HAS_P3SEL2__))
  169.    (const uint16_t) (&P3SEL2),
  170. #else
  171.         NOT_A_PORT,
  172. #endif
  173. };


  174. /*
  175. * Defines for devices with 2x TA3 timers (e.g. MSP430g2553). On the 20pin devices, upto 3 analog outputs are available
  176. * T0A1, T1A1 and T1A2
  177. */
  178. const uint8_t digital_pin_to_timer[] = {
  179.    NOT_ON_TIMER, /*  dummy */
  180.    NOT_ON_TIMER, /*  1 - VCC */
  181.    NOT_ON_TIMER, /*  2 - P1.0 */
  182.    NOT_ON_TIMER, /*  3 - P1.1, note: A0 output cannot be used with analogWrite */
  183.    T0A1,         /*  4 - P1.2 */
  184.    NOT_ON_TIMER, /*  5 - P1.3 */
  185.    NOT_ON_TIMER, /*  6 - P1.4 note: special case. Leaving as no timer due to difficulty determining if available */
  186.    NOT_ON_TIMER, /*  7 - P1.5 note: A0 output cannot be used with analogWrite  */
  187. #if defined(__MSP430_HAS_T1A3__)
  188.    NOT_ON_TIMER, /*  8 - P2.0 note: A0 output cannot be used with analogWrite */
  189.    T1A1,         /*  9 - P2.1 */
  190.    T1A1,         /* 10 - P2.2 */
  191.    NOT_ON_TIMER, /* 11 - P2.3 note: A0 output cannot be used with analogWrite  */
  192.    T1A2,         /* 12 - P2.4 */
  193.    T1A2,         /* 13 - P2.5 */
  194. #else
  195.    NOT_ON_TIMER, /*  8 - P2.0 */
  196.    NOT_ON_TIMER, /*  9 - P2.1 */
  197.    NOT_ON_TIMER, /* 10 - P2.3 */
  198.    NOT_ON_TIMER, /* 11 - P2.4 */
  199.    NOT_ON_TIMER, /* 12 - P2.5 */
  200.    NOT_ON_TIMER, /* 13 - P2.6 */
  201. #endif
  202.    T0A1,         /* 14 - P1.6 */
  203.    NOT_ON_TIMER, /* 15 - P1.7 */
  204.    NOT_ON_TIMER, /* 16 - /RESET */  
  205.    NOT_ON_TIMER, /* 17 - TEST */  
  206.    NOT_ON_TIMER, /* 18 - XOUT - P2.7 */
  207.    T0A1,         /* 19 - XIN - P2.6: */
  208.    NOT_ON_TIMER, /* 20 - GND */
  209. };

  210. const uint8_t digital_pin_to_port[] = {
  211.    NOT_A_PIN, /* dummy */
  212.    NOT_A_PIN, /* 1 */
  213.    P1, /* 2 */
  214.    P1, /* 3 */
  215.    P1, /* 4 */
  216.    P1, /* 5 */
  217.    P1, /* 6 */
  218.    P1, /* 7 */
  219.    P2, /* 8 */
  220.    P2, /* 9 */
  221.    P2, /* 10 */
  222.    P2, /* 11 */
  223.    P2, /* 12 */
  224.    P2, /* 13 */
  225.    P1, /* 14 */
  226.    P1, /* 15 */
  227.    NOT_A_PIN, /* 16 */
  228.    NOT_A_PIN, /* 17 */
  229.    P2, /* 18 */
  230.    P2, /* 19 */
  231.    NOT_A_PIN, /* 20 */
  232. };

  233. const uint8_t digital_pin_to_bit_mask[] = {
  234.    NOT_A_PIN, /* 0,  pin count starts at 1 */
  235.    NOT_A_PIN, /* 1,  VCC */
  236.    BV(0),     /* 2,  port P1.0 */
  237.    BV(1),     /* 3,  port P1.1 */
  238.    BV(2),     /* 4,  port P1.2 */
  239.    BV(3),     /* 5,  port P1.3*/
  240.    BV(4),     /* 6,  port P1.4 */
  241.    BV(5),     /* 7,  port P1.5 */
  242.    BV(0),     /* 8,  port P2.0 */
  243.    BV(1),     /* 9,  port P2.1 */
  244.    BV(2),     /* 10, port P2.2 */
  245.    BV(3),     /* 11, port P2.3 */
  246.    BV(4),     /* 12, port P2.4 */
  247.    BV(5),     /* 13, port P2.5 */
  248.    BV(6),     /* 14, port P1.6 */
  249.    BV(7),     /* 15, port P1.7 */
  250.    NOT_A_PIN, /* 16, RST */
  251.    NOT_A_PIN, /* 17, TEST */
  252.    BV(7),     /* 18, XOUT */
  253.    BV(6),     /* 19, XIN */
  254.    NOT_A_PIN, /* 20, GND */
  255. };
  256. const uint32_t digital_pin_to_analog_in[] = {
  257.         NOT_ON_ADC,     /*  dummy   */
  258.         NOT_ON_ADC,     /*  1 - 3.3V*/
  259.         0,            /*  2 - A0 */
  260.         1,              /*  3 - A1 */
  261.         2,             /*  4 - A2 */
  262.         3,             /*  5 - A3 */
  263.         4,             /*  6 - A4 */
  264.         5,            /*  7 - A5 */
  265.         NOT_ON_ADC,    /*  8 - P2.0 */
  266.         NOT_ON_ADC,    /*  9 - P2.1 */
  267.         NOT_ON_ADC,    /*  10 - P2.2 */
  268.         NOT_ON_ADC,    /*  11 - P2.3 */
  269.         NOT_ON_ADC,    /*  12 - P2.4 */
  270.         NOT_ON_ADC,    /*  13 - P2.5 */
  271.         6,              /*  14 - A6 */
  272.         7,              /*  15 - A7 */
  273.         NOT_ON_ADC,    /*  16 - RST */
  274.         NOT_ON_ADC,     /*  17 - PF0 */
  275.         NOT_ON_ADC,    /*  18 - PE0 */
  276.         NOT_ON_ADC,     /*  19 - PB2 */
  277.         NOT_ON_ADC     /*  20 - GND */
  278. };

  279. #endif
  280. #endif


 楼主| gaoyang9992006 发表于 2020-3-1 11:00 | 显示全部楼层
本帖最后由 gaoyang9992006 于 2020-3-1 11:01 编辑

对于测试PWM的功能,可以找到基本例程的fade
  1. /*
  2.   Fade

  3.   This example shows how to fade an LED on pin 14
  4.   using the analogWrite() function.

  5.   Hardware Required:
  6.   * MSP-EXP430G2 LaunchPad
  7.   
  8.   This example code is in the public domain.

  9. */

  10. int brightness = 0;    // how bright the LED is
  11. int fadeAmount = 5;    // how many points to fade the LED by

  12. void setup()  {
  13.   // declare pin 14 to be an output:
  14.   pinMode(GREEN_LED, OUTPUT);
  15. }

  16. void loop()  {
  17.   // set the brightness of pin 9:
  18.   analogWrite(GREEN_LED, brightness);   

  19.   // change the brightness for next time through the loop:
  20.   brightness = brightness + fadeAmount;

  21.   // reverse the direction of the fading at the ends of the fade:
  22.   if (brightness == 0 || brightness == 255) {
  23.     fadeAmount = -fadeAmount ;
  24.   }     
  25.   // wait for 30 milliseconds to see the dimming effect   
  26.   delay(30);                           
  27. }

即可完美的体验一把PWM的超级简单的操作方式。使用analogWrite()函数,指定管脚编号,指定输出值,0到255,0表示关闭,255为100%占空比,共计255个划分。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:如果你觉得我的分享或者答复还可以,请给我点赞,谢谢。

2052

主题

16405

帖子

222

粉丝
快速回复 在线客服 返回列表 返回顶部