楼主: NXP管管

[在线活动] 【送70块板卡】“中秋芯礼”开发板大放送

  [复制链接]
回帖奖励 27 NXP金币 回复本帖可获得 3 NXP金币奖励! 每人限 2 次
抢楼 抢楼 查看抢中楼层 本帖为抢楼帖,欢迎抢楼!  奖励楼层: 7,77,177 
  • TA的每日心情
    奋斗
    2024-11-27 09:11
  • 签到天数: 30 天

    连续签到: 1 天

    [LV.5]常住居民I

    0

    主题

    63

    帖子

    0

    注册会员

    Rank: 2

    积分
    148
    最后登录
    2024-11-27
    发表于 2024-9-23 10:30:29 | 显示全部楼层

    回帖奖励 +3 NXP金币

    在一次项目开发中,遇到了一个问题:使用 memcpy 将字符串复制到结构体时,出现了字节丢失的情况。经过调查,发现问题的根源在于字节对齐。
    1. // 修改前
    2. typedef struct typedef_struct1 {
    3.    uint8_t ucbyte1;
    4.    uint8_t ucbyte2;
    5.    uint8_t ucbyte3;
    6.    uint8_t ucbyte4;
    7.    uint8_t ucbyte5;
    8. } struct1_type;

    9. typedef struct typedef_struct2 {
    10.    uint8_t ucbyte1;
    11.    uint8_t ucbyte2;
    12.    uint8_t ucbyte3;
    13.    uint8_t ucbyte4;
    14.    uint8_t ucbyte5;
    15.    uint8_t ucbyte6;
    16.    uint8_t ucbyte7;
    17.    uint8_t ucbyte8;
    18. } struct2_type;

    19. typedef struct typedef_struct3 {
    20.    struct1_type        sstruct1;
    21.    struct2_type sstruct2;
    22. } struct3_type;
    复制代码
    1. // 修改后
    2. typedef struct typedef_struct1 {
    3.    uint8_t ucbyte1;
    4.    uint8_t ucbyte2;
    5.    uint8_t ucbyte3;
    6.    uint8_t ucbyte4;
    7.    uint8_t ucbyte5;
    8. } struct1_type;

    9. typedef struct typedef_struct2 {
    10.    uint8_t ucbyte1;
    11.    uint8_t ucbyte2;
    12.    uint8_t ucbyte3;
    13.    uint8_t ucbyte4;
    14.    uint8_t ucbyte5;
    15.    uint8_t ucbyte6;
    16.    uint8_t ucbyte7;
    17.    uint8_t ucbyte8;
    18. } struct2_type;

    19. typedef struct __attribute__((packed)) typedef_struct3 {
    20.    struct1_type        sstruct1;
    21.    struct2_type sstruct2;
    22. } struct3_type;
    复制代码
    1. // 效果
    2. char str[] = "abcdefghijklmnopqrstuvwxyz";
    3. struct3_type sstruct3 = {0};
    4. memcpy((char *)&sstruct3, str, sizeof(sstruct3));

    5. // 取消对齐前 打印出来的效果是
    6. sstruct3 = {{a,b,c,d,e},{i,j,k,l,m,n,o,p}};

    7. // 取消对齐后 打印出来的效果是
    8. sstruct3 = {{a,b,c,d,e},{f,g,h,i,j,k,l,m}};
    复制代码
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 16:35
  • 签到天数: 1180 天

    连续签到: 26 天

    [LV.10]以坛为家III

    6

    主题

    7094

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    9233
    最后登录
    2025-8-2
    发表于 2024-9-23 14:55:39 | 显示全部楼层

    回帖奖励 +3 NXP金币

    曾经出过强制转换uint8_t *到uint32_t *就可能会HARDFAULT
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 21:43
  • 签到天数: 2486 天

    连续签到: 7 天

    [LV.Master]伴坛终老

    17

    主题

    5368

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    11224
    最后登录
    2025-8-2
    发表于 2024-9-23 18:45:17 | 显示全部楼层

    回帖奖励 +3 NXP金币

    以前有个项目电源匹配不好,电机启动的时候把电压拉下来,有时候会停机,,,后面设计都要好好核算下
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    开心
    前天 15:31
  • 签到天数: 1106 天

    连续签到: 24 天

    [LV.10]以坛为家III

    28

    主题

    4280

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    5804
    最后登录
    2025-8-1
    发表于 2024-9-23 20:47:35 | 显示全部楼层
    在一块板子上已经能正常运转的程序,到另一块板子上运行失败。查了好久,最后才发现,原来是主频不一致。在新板子上由于时钟太快,导致程序无法正常运行。所以移植程序时,必须要考虑时序和时钟匹配的问题。
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    开心
    昨天 22:30
  • 签到天数: 1250 天

    连续签到: 173 天

    [LV.10]以坛为家III

    1

    主题

    2960

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    7637
    最后登录
    2025-8-2
    发表于 2024-9-23 21:46:14 | 显示全部楼层

    回帖奖励 +3 NXP金币

    来自Coral的Dev Board Micro ,使用RT1176作为MCU,板载TPU,可以结合NXP的eIQ进行机器学习应用
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-9-29 09:02
  • 签到天数: 11 天

    连续签到: 1 天

    [LV.3]偶尔看看II

    0

    主题

    29

    帖子

    0

    注册会员

    Rank: 2

    积分
    108
    最后登录
    2024-9-29
    发表于 2024-9-23 23:09:10 来自手机 | 显示全部楼层
    用esp32写的一个天气站,http请求天气接口数据,总是会跑飞,调试了好几次才想起内存不足这回事,后面自己写了一个页面进行中转数据。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    昨天 13:58
  • 签到天数: 346 天

    连续签到: 6 天

    [LV.8]以坛为家I

    12

    主题

    1118

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    2574
    最后登录
    2025-8-2
    发表于 2024-9-24 01:05:24 | 显示全部楼层
    通过 SPI 接口驱动一个 TFT LCD,第一版程序运行慢,是刷一个点更新一个点坐标再写像素值。
    后来第二版想提高速度,更新一个矩形坐标,再通过DMA发送数据,死活没有更新屏幕。

    查了两天都没发现问题,后来灵光一闪,是不是 CS 线没有拉高拉低,果然重新配CS就可以了。
    哎...今天够累的,签到来了~
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    前天 10:23
  • 签到天数: 2096 天

    连续签到: 2 天

    [LV.Master]伴坛终老

    65

    主题

    8413

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    14222
    最后登录
    2025-8-1
    发表于 2024-9-24 15:34:23 | 显示全部楼层
    这段时间在玩玩micropython
    def do_connect():
        #尝试读取配置文件wifi_confi.json,这里我们以json的方式来存储WIFI配置,没有的话要shell手动输入账号密码
        #wifi_config.json在根目录下

        try:                                                                #若不是初次运行,则将文件中的内容读取并加载到字典变量 config
            with open('wifi_config.json','r') as f:
                config = json.loads(f.read())
        except:                                                                #若初次运行,则将进入excpet,执行配置文件的创建
            wlan = network.WLAN(network.STA_IF)
            wlan.active(True)
            print(wlan.scan())                                #打印扫描到的wifi信息
            essid = input('wifi name:')         #输入essid
            password = input('wifi passwrod:') #输入password
            config = dict(essid=essid, password=password) #创建字典
            with open('wifi_config.json','w') as f:
                f.write(json.dumps(config)) #将字典序列化为json字符串,存入wifi_config.json

        #以下为正常的WIFI连接流程        
        wifi = network.WLAN(network.STA_IF)  
        if not wifi.isconnected():
            print('connecting to network...')
            wifi.active(True)                                 #激活网络接口
            wifi.connect(config['essid'], config['password']) #从字典中获取wifi信息
            time.sleep(5)                                         #一般睡个5-10秒,应该绰绰有余

            if not wifi.isconnected():
                wifi.active(False)                         #关掉连接,免得repl死循环输出
                print('wifi connection error, please reconnect')
                #连续输错essid和password会导致wifi_config.json不存在
                try:
                    os.remove('wifi_config.json') # 第一次配网输错wifi信息,将删除配置文件               
                except:
                    pass
                do_connect() # 重新连接
        else:
            print('Wifi connection succeeded')
            print('network config:', wifi.ifconfig())

    回复

    使用道具 举报

  • TA的每日心情
    开心
    6 小时前
  • 签到天数: 949 天

    连续签到: 7 天

    [LV.10]以坛为家III

    14

    主题

    4469

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    7543
    最后登录
    2025-8-3
    发表于 2024-9-24 15:40:10 | 显示全部楼层
    通过SPI 接口驱动一个 TFT LCD
    时不时显示不正常,花屏,
    最后是把SPI速率调低解决。
    永远开心快乐
    回复

    使用道具 举报

  • TA的每日心情
    开心
    前天 15:31
  • 签到天数: 1106 天

    连续签到: 24 天

    [LV.10]以坛为家III

    28

    主题

    4280

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    5804
    最后登录
    2025-8-1
    发表于 2024-9-24 22:39:15 | 显示全部楼层
    51单片机读写24C64的程序
    #include <reg51.h>
    #include <delay.h>
    #include <at24c64.h>

    bit I2C_Start(void) {
        delay_us(10);
        I2C_SDA =1;
        delay_us(10);
        I2C_SCK =1;
        delay_us(10);
        if ( I2C_SDA == 0) return 0;
        if ( I2C_SCK == 0) return 0;
        I2C_SDA = 0;
        delay_us(10);
        I2C_SCK = 0;
        delay_us(10);
        return 1;
    }

    void  I2C_Stop(void) {
        delay_us(10);
        I2C_SDA = 0;
        delay_us(10);
        I2C_SCK = 1;
        delay_us(10);
        I2C_SDA = 1;
        delay_us(10);
    }

    void I2C_Ack(void)  {
        delay_us(10);
        I2C_SDA=0;
        delay_us(10);
        I2C_SCK=1;
        delay_us(10);
        I2C_SCK=0;
        delay_us(10);
    }

    void I2C_Nack(void) {
        delay_us(10);
        I2C_SDA=1;
        delay_us(10);
        I2C_SCK=1;
        delay_us(10);
        I2C_SCK=0;
        delay_us(10);
    }

    bit I2C_Send_Byte( uchar d) {
        uchar i = 8;
        bit bit_ack;
        while( i-- )  {
            delay_us(10);
            if (d & 0x80 )   I2C_SDA =1;
            else             I2C_SDA =0;
            delay_us(10);
            I2C_SCK = 1;
            delay_us(10);
            I2C_SCK = 0;
            d = d << 1;
        }
        delay_us(10);
        I2C_SDA = 1;
        delay_us(10);
        I2C_SCK = 1;
        delay_us(10);
        bit_ack = I2C_SDA;
        I2C_SCK =0;
        delay_us(10);
        return bit_ack;
    }

    uchar I2C_Receive_Byte(void) {
        uchar i = 8, d;
        delay_us(10);
        I2C_SDA = 1;
        while ( i--)     {
            d = d << 1;
            delay_us(10);
            I2C_SCK =1;
            if ( I2C_SDA ) d++;
            delay_us(10);
            I2C_SCK =0;
        }
        return d;
    }

    void AT24C64_W(void *mcu_address,uint AT24C64_address,uint count)  {
        //DOG_WDI=!DOG_WDI;
        //DOGTIME=0;
        I2C_WP=0;
        while(count--)      {
            I2C_Start();
            /*I2C_Send_Byte( 0xa0 + AT24C64_address /256 *2);*/  /* 24C16  USE */
            I2C_Send_Byte( 0xa0 );
            I2C_Send_Byte(  AT24C64_address/256 );
            I2C_Send_Byte( AT24C64_address %256 );
            I2C_Send_Byte( *(uchar*)mcu_address );
            I2C_Stop();
            delay_ms(10);       /* waiTIng for write cycle to be completed */
            ((uchar*)mcu_address)++;
            AT24C64_address++;
        }
        I2C_WP=1;
    }

    void AT24C64_R(void *mcu_address,uint AT24C64_address,uint count) {
        while(count--) {
            I2C_Start();
            /*I2C_Send_Byte( 0xa0 + AT24C64_address / 256 *2 );*/   /* 24C16 USE */
            I2C_Send_Byte( 0xa0 );
            I2C_Send_Byte( AT24C64_address/256 );
            I2C_Send_Byte( AT24C64_address % 256 );
            I2C_Start();
            /*I2C_Send_Byte( 0xa1 + AT24C64_address /256 *2 );*/
            I2C_Send_Byte( 0xa1 );
            *(uchar*)mcu_address = I2C_Receive_Byte();
            I2C_Nack();
            I2C_Stop();
            ((uchar*)mcu_address)++;
            AT24C64_address++;
        }
    }

    哎...今天够累的,签到来了~
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /3 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2025-8-3 15:44 , Processed in 0.102303 second(s), 27 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

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