盗图了,要在mbed程序中使用这些PIN啥的,叫啥名必须知道
这两个图很有价值
These headers give access to all STM32 pins.
图中蓝底白字或者绿底白字的标签名,是可以直接在程序中使用的。
其它颜色的是为了提供些信息啥的,不能用再程序中。
除此之外,这些定义是可以在程序中使用的
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,
是不是豁然开朗?
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);
不过还好我们有
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;
这样是不是优雅多了?
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/
| 有奖活动 | |
|---|---|
| 硬核工程师专属补给计划——填盲盒 | |
| “我踩过的那些坑”主题活动——第002期 | |
| 【EEPW电子工程师创研计划】技术变现通道已开启~ | |
| 发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
| 【EEPW在线】E起听工程师的声音! | |
| 高校联络员开始招募啦!有惊喜!! | |
| 【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
| 送您一块开发板,2025年“我要开发板活动”又开始了! | |