这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » STM32 » NUCLEO L053R8 边学边玩

共34条 2/4 1 2 3 4 跳转至
专家
2015-10-30 23:14:48     打赏
11楼

盗图了,要在mbed程序中使用这些PIN啥的,叫啥名必须知道

这两个图很有价值



Nucleo pinout Arduino-compatible headers





Morpho headers

These headers give access to all STM32 pins.



专家
2015-10-30 23:29:07     打赏
12楼

图中蓝底白字或者绿底白字的标签名,是可以直接在程序中使用的。

其它颜色的是为了提供些信息啥的,不能用再程序中。


除此之外,这些定义是可以在程序中使用的

SERIAL_TX=PA_2  I2C_SCL=PB_8  SPI_MOSI=PA_7  PWM_OUT=PB_3
SERIAL_RX=PA_3  I2C_SDA=PB_9  SPI_MISO=PA_6
                              SPI_SCK =PA_5
                              SPI_CS  =PB_6
其实的别被一大堆标签和名字吓到,也别被两组接口吓到:

我发现以下两点:

(1)Arduino接口,其实就是和挨着的那排口直接短接的
(2)Arduino接口带的标签,其实就是对应接口定义个别名而已

这么重大的发现,是不是可以获得诺贝尔奖或者图灵奖啥的?


详细的内容如下:

    // Arduino connector namings
    A0          = PA_0,
    A1          = PA_1,
    A2          = PA_4,
    A3          = PB_0,
    A4          = PC_1,
    A5          = PC_0,
    D0          = PA_3,
    D1          = PA_2,
    D2          = PA_10,
    D3          = PB_3,
    D4          = PB_5,
    D5          = PB_4,
    D6          = PB_10,
    D7          = PA_8,
    D8          = PA_9,
    D9          = PC_7,
    D10         = PB_6,
    D11         = PA_7,
    D12         = PA_6,
    D13         = PA_5,
    D14         = PB_9,
    D15         = PB_8,
 
    // Generic signals namings
    LED1        = PA_5,
    LED2        = PA_5,
    LED3        = PA_5,
    LED4        = PA_5,
    USER_BUTTON = PC_13,
    SERIAL_TX   = PA_2,
    SERIAL_RX   = PA_3,
    USBTX       = PA_2,
    USBRX       = PA_3,
    I2C_SCL     = PB_8,
    I2C_SDA     = PB_9,
    SPI_MOSI    = PA_7,
    SPI_MISO    = PA_6,
    SPI_SCK     = PA_5,
    SPI_CS      = PB_6,
    PWM_OUT     = PB_3,

 

是不是豁然开朗?


专家
2015-11-02 14:49:25     打赏
13楼
跟着卓大学nucleo

专家
2015-11-04 10:33:39     打赏
14楼

又学习了几天,成果不是很显著

说实话,还是Arduino简单啊,而我这种低智商的生物,当然喜欢简单的东西了。


擦,刚想贴点代码上来,发现mbed的站点死翘翘了

可惜了我文思泉涌,一下子就被打断了



菜鸟
2015-11-04 15:37:32     打赏
15楼
支持卓泰大神

专家
2015-11-04 15:42:42     打赏
16楼

mbed还没康复

莫非和google一样悲催啦




专家
2015-11-04 15:49:13     打赏
17楼

我冤枉伟大的D和ZF了。

原本以为是因为G-F-W的问题打不开

结果用工具测试了一下,从国外也打不开

话说已经5-6个小时啦。

所以基于web的IDE啥的还是不靠谱呀



专家
2015-11-04 15:54:11     打赏
18楼

回头和大神学用keil玩吧

话说十五六年没用keil了,忘干净鸟,即使没忘干净,现在的变化也应该老大了吧



专家
2015-11-05 16:59:25     打赏
19楼

nucleo的RTC


昨天先是mbed站点坏掉

然后等了好几个小时,mbed终于康复了

然后EEPW服务器的网线又被老鼠咬断了


说一下nucleo的RTC吧

话说这个stm32L053R8处理器是带RTC的

(这里写着呢,https://developer.mbed.org/platforms/ST-Nucleo-L053R8/)


mbed也提供了一个显示时间的例子(尽管有点简陋):


#include "mbed.h"
 
DigitalOut myled(LED1);
 
int main() {
    
    printf("RTC example\n"); 
    set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
    printf("Date and time are set.\n");
 
    while(1) {
 
        time_t seconds = time(NULL);
 
        //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
        
        printf("Time as a basic string = %s", ctime(&seconds));
 
        //char buffer[32];
        //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
        //printf("Time as a custom formatted string = %s", buffer);
 
        myled = !myled;      
        wait(1);
    }
}


其实核心就是这个set_time()


/** Set the current time
 *
 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
 * to the time represented by the number of seconds since January 1, 1970
 * (the UNIX timestamp).
 *
 * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
 *
 * Example:
 * @code
 * #include "mbed.h"
 *
 * int main() {
 *     set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
 * }
 * @endcode
 */
void set_time(time_t t);


不过这个其实很不方便,鬼知道1256729737咋查出来了


不过还好我们有

struct tm {
    int tm_sec;   /* seconds after the minute, 0 to 60
                     (0 - 60 allows for the occasional leap second) */
    int tm_min;   /* minutes after the hour, 0 to 59 */
    int tm_hour;  /* hours since midnight, 0 to 23 */
    int tm_mday;  /* day of the month, 1 to 31 */
    int tm_mon;   /* months since January, 0 to 11 */
    int tm_year;  /* years since 1900 */
    int tm_wday;  /* days since Sunday, 0 to 6 */
    int tm_yday;  /* days since January 1, 0 to 365 */
    int tm_isdst; /* Daylight Savings Time flag */
    union {       /* ABI-required extra fields, in a variety of types */
        struct {
            int __extra_1, __extra_2;
        };
        struct {
            long __extra_1_long, __extra_2_long;
        };
        struct {
            char *__extra_1_cptr, *__extra_2_cptr;
        };
        struct {
            void *__extra_1_vptr, *__extra_2_vptr;
        };
    };
};


我们还有:
extern _ARMABI time_t mktime(struct tm * /*timeptr*/) __attribute__((__nonnull__(1)));
/*
* converts the broken-down time, expressed as local time, in the structure
* pointed to by timeptr into a calendar time value with the same encoding
* as that of the values returned by the time function. The original values
* of the tm_wday and tm_yday components of the structure are ignored, and
* the original values of the other components are not restricted to the
* ranges indicated above. On successful completion, the values of the
* tm_wday and tm_yday structure components are set appropriately, and the
* other components are set to represent the specified calendar time, but
* with their values forced to the ranges indicated above; the final value
* of tm_mday is not set until tm_mon and tm_year are determined.
* Returns: the specified calendar time encoded as a value of type time_t.
*          If the calendar time cannot be represented, the function returns
*          the value (time_t)-1.
*/

 




所以我们可以这样:

	 struct tm mytime;
	 time_t seconds;
	

	 mytime.tm_year = xxx;
         mytime.tm_mon = xxx;	 
	 ....

然后:
         seconds = mktime(&mytime);
	 set_time(seconds);



记得年是从1900年开始的,所以如果你需要存2015,那么赋值应该写成:
mytime.tm_year = 2015 - 1900;


同理月是从0开始的,所以,如果你想保存11月,那么赋值部分应该写:
mytime.tm_mon = 11-1;


这样是不是优雅多了?


专家
2015-11-05 17:25:29     打赏
20楼

nucleo的RTC续(一)


好吧,程序挺优雅的,自己先吐,免得被你们吐。

STM32L053R8带个RTC也挺优雅

mbed提供了rtc的读写也挺优雅

都优雅,那么貌似不用写什么续集了,骗字数也不能这样不厚道吧?


其实不然,别看楼主平时做事低调,但是做人是相当厚道的。

废话少说(其实是说了很多废话说不动了):

举个栗子,你买个手机,设置好时间后,关机再开机,时间又变成1900年1月1日,你啥心情

这个nucleo就系这样,新都睡了

设置完时间,不断电,按reset,时间就木有啦。


大神的改造,话说我完全看不懂他做的啥,画的啥。感兴趣的去看看

https://developer.mbed.org/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/


共34条 2/4 1 2 3 4 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]