在cubemx配置好adc,和串口(阻塞)
function [nbChar,buff] = convert(u) if coder.target('Sfun') buff = uint32(0); nbChar = uint16(0); else coder.cinclude('stdio.h'); coder.cinclude('main.h'); coder.cinclude('getBuffPtr.h'); string = char(zeros(1,20)); stringSize = uint16(size(string,2)); stringFormat = char(['%08x-%5.2f V',13.10,0]); tick = uint32(0); tick = coder.ceval('HAL_GetTick'); %tick 08x u 5.2f coder.ceval('snprintf',coder.wref(string), stringSize, coder.rref(stringFormat), tick, u) buff = coder.ceval('getBuffPtr',coder.wref(string)); nbChar = stringSize;%其实给的多了,应该只给到0X00 end end