基于N32G003的PMBus从机协议栈设计与STM32F103模拟I2C主机通信实战

PMBus < SMBus < I2C 关系解析 SMBus 全称 System Management Bus,即系统管理总线。SMBUS 是一种基于I2C而扩展出来的协议,是 I2C 协议的一个子集。但SMBus 要求更严格,规 定了更多细节与规范。有一些更为复杂的操作,但是原理都还是基于I2C的。SMBus 也被用来连接各种设备,包括电源相关设备,系统传感器,EEPROM 通讯设备等等。SMBus 为系统和电源管理这样的任务提供了一条控制总线,使用 SMBus 的系统,设备之间发送 和接收消息都是通过 SMBus,而不是使用单独的控制线,这 阅读详情

1. PMBus协议与工业电源管理实战背景

在工业电源管理系统中,PMBus(Power Management Bus)协议凭借其开放性和灵活性,成为电源设备通信的重要标准。它基于I2C物理层,通过定义丰富的命令集实现对电源参数的监控和控制。最近我在一个工业电源项目中采用了国民技术的N32G003作为PMBus从机,配合STM32F103模拟I2C主机进行通信,实测在70kHz速率下稳定可靠。这种方案特别适合对成本敏感且需要精细化电源管理的应用场景,比如服务器电源、通信基站和工业自动化设备。

N32G003作为一款ARM Cortex-M0内核的MCU,具备丰富的外设资源和低功耗特性,非常适合作为PMBus从机设备。而STM32F103虽然本身有硬件I2C外设,但在某些多主机竞争或特殊时序要求的场景下,模拟I2C反而能提供更好的灵活性和控制精度。在实际项目中,这种组合既满足了协议要求,又实现了BOM成本的最优化。

2. N32G003的PMBus从机协议栈设计

2.1 中断驱动架构设计

在N32G003上实现PMBus从机协议栈时,我采用了中断驱动的架构。核心是通过I2C从机中断处理各种总线事件,包括地址匹配、数据接收和发送完成等。中断服务程序需要高效处理以下关键事件:

void I2C_EV_IRQHandler(void) {
    uint32_t last_event = I2C_Last_Event_Get(I2C);
    switch (last_event) {
        case I2C_EVT_SLAVE_RECV_ADDR_MATCHED:
            // 处理地址匹配事件
            break;
        case I2C_EVT_SLAVE_DATA_RECVD:
            // 处理数据接收事件
            break;
        case I2C_EVT_SLAVE_DATA_SENDING:
            // 处理数据发送事件
            break;
    }
}

这种设计确保了实时响应主机请求,同时避免了轮询方式带来的CPU资源浪费。在实际测试中,中断响应时间控制在5μs以内,完全满足PMBus的时序要求。

2.2 命令解析与数据处理

PMBus协议定义了丰富的命令集,从机需要正确解析并执行这些命令。我采用查表法实现命令分发,通过switch-case结构处理不同类型的命令:

unsigned char PMBusSlave_DecodeCommand(unsigned char PMBusSlave_RxComma
从零构建PMBus通信:N32G003与STM32F103的I2C模拟实战解析 本文详细解析了如何基于国民技术N32G003的硬件I2C从机与STM32F103的模拟I2C主机,从零构建一套稳定可靠的PMBus通信系统。内容涵盖PMBus协议核心机制、硬件初始化配置、中断驱动状态机设计、PEC校验算法优化以及精确时序控制实现,为嵌入式电源管理系统开发提供实战指导。 阅读详情

相关推荐

PMBus1.3协议

电源管理总线(“PMBus”)是一个开放的协议,它定义了功率变换器和其他器件之间的通信方式。

pmbus协议栈用户指南.pdf

PMBus(电源管理总线)是一种开放标准的数字电源管理协议。可通过定义传输和物理接口以及命令语言来促进与电源转换器或其他设备的通信。

USB转I2C/IIC/SMBus/PMBus适配器软件

1、读写控制常规I2C接口芯片; 2、SMBus总线协议读写控制支持SMBus总线协议的芯片; 3、PMBus总线协议读写控制支持PMBus总线协议的电源管理芯片; 4、GPIO控制输出,给所控制的芯片输出相关控制信号; 5、所需硬件:纬图USB-I2C适配器

电源管理总线(PMBus)通信协议

电源管理总线(PMBus)通信协议规范定义了一个用在功率转换器件和管理器件之间的数字通信协议(包括接口和命令)。该规范对于数字电源产品的推广有着非常重要的意义,意味着数字电源产品的接口完成了标准化。借助PMBus,数字电源可以依据一套标准命令进行配置、监控和维护(设置电源的工作参数并监控其工作,而且能够在故障发生时采取应对措施),还能使多个数字电源产品协同工作。

接口/总线/驱动中的详解电源管理总线(PMBus)数字电源开放标准协议

PMBus(电源管理总线)开放标准规范定义了一个用来控制功率转换和管理器件的数字通信协议。在供电要求较复杂的系统中,通常使用多个DC/DC转换器来产生不同的半导体器件所需要的供电要求。导致一个明显结果就是在产品设计、生产测试及日常使用的过程中,控制和监测这些电源将变得更加复杂。   目前,许多高性能DC/DC转换器仍然通过无源元件产生的模拟信号来进行控制。即使采用最先进的电源电路拓扑,也不得不使用外部的电位器和电容来调节诸如启动时间、输出电压值及开关频率等参数,而且这些参数不能随时更改。   PMBus是一种开放型标准的数字电源管理协议。可通过定义传输和物理接口以及命令语言来实现变换器与其

VS Code + Codex 在 WSL 中使用的正确姿势

Codex 登录只能在本地完成。文件仍可通过 UNC 路径访问 WSL → 本地 Codex 就能照常工作。避免在 WSL 内重复安装/登录 Codex 扩展。

yangguangwuyue的博客 9887

Halcon dyn_threshold详解

dyn_threshold 原型 dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : ) 功能 利用局部阈值分割图像 参数列表 OrigImage (input_object):原始图像 ThresholdImage (input_object):处理后图像(一般采用滤波处理) RegionDynThresh (output_object):分割后区域 Offset (input_control):灰

ZiLiangQin的博客 1万+

STM32输入捕获功能,同时捕获8路波形。

STM32输入捕获功能,使用TIM2和TIM3同时捕获8路波形。 工作上的一个需求,要采集两组控制步进电机的信号。就是采集8个通道的方波,测量频率和计脉冲个数。看起来简简单单的东西,磕磕碰碰搞了两天,走了一些弯路,这里写出来记录一下。顺便理解一下输入捕获个多种用法。 1. 硬件设计 首先看一下用到那些IO口。在STM32手册里找这样TIMx_CHx的就是输入捕获的口了。 这里用了TIM2的4个口和TIM3的4个口。 定义 端口 TIM2_CH1 PA0 TIM2_CH2 PA1 TI

qq_36353009的博客 5127

告别CANoe?手把手教你用Python+PCAN搭建汽车诊断脚本(附完整代码)

本文详细介绍了如何利用Python和PCAN硬件搭建高性价比的汽车诊断自动化方案,替代昂贵的CANoe工具。通过开源库python-can和udsoncan实现UDS诊断协议,涵盖硬件选择、环境配置、核心功能实现及性能优化,附完整代码示例,助力开发者快速构建诊断脚本。

weixin_42551227的博客 377

攻防实战之Confluence后利用

这边管理员密码是密文加密在数据库中,解不开,因此解决的思路是将管理员用户密码修改为已知明文密码的密文(这边不能直接在数据库中添加字段,关系型数据库在单表中添加一条字段可能会出现问题),登录上后台以后,添加用户并加入管理员组,最后将管理员密码还原。Confluence的后利用主要问题在于在Linux中搭建时,默认是Confluence用户权限,如下图所示,而confluence在linux中是没有写权限的,这也就是为什么有些人发现可以执行命令但是shell写不进去。至此admin的密码被改为了123123。

weixin_39251927的博客 2717

告别臃肿VS!仅用Visual Studio 2022 Build Tools为Qt 5.12.12配置MSVC2017开发环境

本文详细介绍了如何仅使用Visual Studio 2022 Build Tools为Qt 5.12.12配置MSVC2017开发环境,避免安装臃肿的完整VS。通过精准选择组件、配置Qt Creator编译器和优化Kit设置,实现高效、精简的Windows平台Qt开发环境搭建,特别适合追求性能和资源优化的开发者。

weixin_30340617的博客 356

RK3588S之CPU--benchmark(一)

本章会基于RK3588S来介绍有关CPU常用的benchmark工具及测试过程

文艺小少年的博客 1500

嵌入式工程师成长之路(2)——电路设计

为什么你的电源模块总是发热炸机?DC/DC和LDO选型的“潜规则”你踩坑了吗? LM2596降压芯片用错电容导致输出振荡?LED恒流驱动设计让灯珠寿命缩水50%?24V转12V方案成本超预算被老板狂喷?——这些血泪教训,谁能懂得!

云轩阁 13万+

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 蓝桥杯单片机赛项实战复盘:真题解析与时间管理策略
下一篇: FPGA实战:SPI接口驱动TLV5618双通道DAC实现精密电压输出
咖啡因依赖
博客等级 码龄4年 51粉丝 1687原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址