完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
美好的一天。我正在为LIS2DH12(LIS2DH12_ACC_driver.c)尝试ST标准组件驱动程序我已将它添加到我的项目中,但编译器会发出未定义的符号错误。这是我所期望的,因为我没有定义以下任何一项。
extern uint8_t Sensor_IO_Read(void * handle,uint8_t ReadAddr,uint8_t * pBuffer,uint16_t nBytesToRead); extern uint8_t Sensor_IO_Write(void * handle,uint8_t WriteAddr,uint8_t * pBuffer,uint16_t nBytesToWrite); 我想弄清楚我需要定义什么以及在哪里?我可以看到它的I2C R / W函数带有某些unsigned int,需要按顺序使用才能读写,但我不知道如何在main.c中声明这些,或者如何与标准一起调用它们在stdPeriph_driver库中的I2C.c。 这两个功能在驱动程序中没有其他功能,所以我需要自己编写吗? 任何解释或方向将不胜感激。 #加速度计的lis2dh12-配置 以上来自于谷歌翻译 以下为原文 Goodday. Im trying out the ST standard component driver for LIS2DH12 (LIS2DH12_ACC_driver.c) I have added it to my project but compiler kicks out a undefined symbol error. Which is what I would expect as I have not defined any of the below. extern uint8_t Sensor_IO_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); extern uint8_t Sensor_IO_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); Im trying to figure out what is required of me to define and where? I can see its an I2C R/W function with certain unsigned int's that needs to be used in that order to read and write, but I have no idea how to declare these in main.c or how to call these in conjunction with the standard I2C.c in stdPeriph_driver library. these two functions are nowhere else in the driver so do I need to write my own? any explanation or direction would be greatly appreciated. #accelerometer-lis2dh12-configure |
|
相关推荐
9个回答
|
|
是的,您必须根据您将使用的MCU和总线(SPI或I2C)为您编写这两个功能。从传感器驱动器调用这些功能以执行读取或写入操作。基本上你应该通过I2C或SPI(来自stdPeriph库)的读/写功能来填充这两个功能。
以上来自于谷歌翻译 以下为原文 Yes, you have to write you own these two function according to your MCU and bus which you will use (SPI or I2C). These function are than called from the sensor driver to perform reading or writing operation. Basically you should fill these two function by the reading / writing function for I2C or SPI (from stdPeriph library). |
|
|
|
谢谢Miroslav。我仍然感到困惑,我的C充其量只是入门级别。当然,如果这两个函数都在ST的驱动文件中(
LIS2DH12_ACC_driver.c)它们应该在那里或.h文件中定义和声明。我应该能够称之为。我怎么知道要将它们定义为什么。我究竟要定义什么? 以上来自于谷歌翻译 以下为原文 Thanks Miroslav. I am still confused my C is entry level at best. Surely if these two functions are in the driver file from ST ( LIS2DH12_ACC_driver.c) they should be defined and declared there or in the .h file. And I should just be able to call it. How would I know what to define them to. What exactly do I define? |
|
|
|
你好,
在这里看看类似的问题和答案: https://community.st.com/0D50X00009XkXf3SAF 你基本上需要在你的目标MCU上做4个步骤(顺便说一句,你使用什么样的硬件?): 1)I2C初始化:在主机模式下启动主机微控制器和I2C 2)找出,如何发送和读取单个寄存器(在特定的器件地址和特定的寄存器地址)。 3)读取多个字节:这就是写一个循环以在上一步发送更多字节。通过使用以下参数实现一个函数,使其更加通用: uint8_t Sensor_IO_Read(void * handle,uint8_t ReadAddr,uint8_t * pBuffer,uint16_t nBytesToRead); 4)写入多个字节:与3)相同,但用于读取一个字节。再次,通过实现具有以下参数的函数使其成为通用: uint8_t Sensor_IO_Write(void * handle,uint8_t WriteAddr,uint8_t * pBuffer,uint16_t nBytesToWrite); 将这些函数写在一个单独的C文件中(因此它的HW独立供将来使用),为此C文件创建一个头文件,并将头文件包含在您发布'extern'声明的文件中。 (或者,如果您对可移植性不太关心或者对您来说似乎太复杂了,(并且您不介意不那么完美的代码)删除'extern'关键字并在同一.c源中定义函数文件作为代码的其余部分是)。 如果你需要一些关于I2C的帮助,我建议在***”(另外也许是你的平台),有很多视频可以帮助你理解,为什么读取adn写入功能需要全部属性。 大卫 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 Hello, Have a look at a similar question and answer here : https://community.st.com/0D50X00009XkXf3SAF .You basically need to do 4 steps on your target MCU (what kind of HW do you use, by the way?): 1) I2C initialization: start your host microcontroller and an I2C in a host mode 2) Find out, how can you send and read a single register (in a specific device address and at a specific register address ). 3) Read multiple bytes: that is just about writing a cycle to send more bytes the previous step. Make it a bit more general by implementing a function with these parameters: uint8_t Sensor_IO_Read(void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead); 4) Write multiple bytes: the same as for 3) , but for reading a byte. Again, make it general by implementing a function with these parameters: uint8_t Sensor_IO_Write(void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite); Write these functions in a separate C file (so its HW independent for your future use), create a header file for this C file and include the header file to the file from where you have posted the 'extern' declarations. (Or, if you don't care that much about portability or it seems too complicated for you, (and you don't mind a not so perfect code) delete the 'extern' keywords and define the functions in the same .c source file as the rest of the code is). If you need some help with I2C generally, I would suggest searching on Youtube for 'I2C tutorial' (additionaly maybe + your platform), there is quite a few videos that will help you get the idea, why the read adn write function need all the attributes. David Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
你好,
它是一个指向句柄的指针,它是HAL概念中使用的c结构。 看看STM32L1 HAL驱动程序的这个描述,第22章: http://www.st.com/content/ccc/resource/technical/document/user_manual/97/4d/5f/9a/ed/e4/4e/66/DM00132099.pdf/files/DM00132099.pdf/jcr:内容/翻译/ en.DM00132099.pdf 如果您是这个概念的新手,我会亲自推荐一个STM在线课程(免费!): http://www.st.com/content/st_com/en/about/events/events.html/stm32cube-basics-online-course-with-hands-on-exercises-a.html 如果涵盖CubeMX配置器和HAL概念,则包含有关真实硬件等的有用示例。 大卫 以上来自于谷歌翻译 以下为原文 Hello, It is a pointer to a handle, that is a c structure used in the HAL concept. Have a look at this description of STM32L1 HAL drivers, chapter 22: http://www.st.com/content/ccc/resource/technical/document/user_manual/97/4d/5f/9a/ed/e4/4e/66/DM00132099.pdf/files/DM00132099.pdf/jcr:content/translations/en.DM00132099.pdf If you are new to this concept, I would personally recommend an STM online course (for free!): http://www.st.com/content/st_com/en/about/events/events.html/stm32cube-basics-online-course-with-hands-on-exercises-a.html If covers CubeMX configurator and HAL concept, contains useful examples on real HW etc. David |
|
|
|
谢谢大卫,我熟悉HAL的存在,但没有机会使用它,这可能是我困惑的原因。我正在使用stdperiph_driver。这个驱动程序还能运行吗?如果是这样,我想我需要在上面的行和下面的行之间编写一些接口。离开驱动程序直接从下面的I2C函数设置LIS2DH12寄存器会不会更容易,我仍然需要将这些寄存器转换为缓冲区。
`void I2C_SendData(I2C_TypeDef * I2Cx,uint8_t Data)` `uint8_t I2C_ReceiveData(I2C_TypeDef * I2Cx)` 以上来自于谷歌翻译 以下为原文 Thanks David, I am familiar with the existence of HAL but have not had the chance to use it and that is probably why I am confused. I am using stdperiph_driver. Would this driver still work? If so, I suppose I need to code some interface between the lines above and lines below. Would it not be easier just to leave the driver and set up the LIS2DH12 registers directly from my I2C functions below, I still need to to convert these to a function as a buffer. `void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data)` `uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx)` |
|
|
|
你好,抱歉迟到了,我度假了。
我不熟悉这些驱动程序,但总有一个选项可以编写自己的驱动程序函数。我个人有时会写它们,因为代码更短更容易阅读。 另一方面,ST为驱动程序提供了最大的兼容性,可能更难以学习如何使用它们,但是更容易跨MCU系列迁移,使用不同的配置设置传感器等。 以上来自于谷歌翻译 以下为原文 Hello, sorry for a late answer, I had a holiday. I am not familiar with these drivers, but there is always an option to write your own driver functions. I personally sometimes write them, because the code is much shorter and easier to read. On the other hand, ST provides the drivers with maximum compatibility in mind, it might be more difficult to learn how to use them, but then it's easier to migrate across MCU families, set the sensors with a different configuration etc. |
|
|
|
我想发布我的解决方案,但这个编辑器除了代码<>所以它作为一个段落出现。有任何想法吗?
以上来自于谷歌翻译 以下为原文 I would like to post my solution but this editor does not except the code <> so it comes up as a paragraph. Any ideas? |
|
|
|
以后进行了大量的研究并查看了其他人的样本,我在STM32L152上附上了对我有用的内容。使用std perph lib函数读取和写入accel LIS2DH12。只读写1个字节。结合了X,Y,Z的LSB和MSB。 LIS2DH12配置没有中断,没有Fifo。
以上来自于谷歌翻译 以下为原文 Lots of research later and looking at samples from others I have attached what is working for me on the STM32L152. read and write to accel LIS2DH12 using std perph lib functions. Reads and writes only 1 byte. combines the LSB and MSB of the X,Y,Z . LIS2DH12 is configured with no interrupts, no Fifo. |
|
|
|
brink.melt.001
你可以添加附件(例如.c文件) 如果您回复帖子,请单击“使用高级编辑器”,然后您可以添加附件。 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 brink.melt.001 you can add attachment (for example .c file) If you reply to the post click on 'Use advanced editor' then you can add the attachment. Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2644 浏览 1 评论
3209 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1784 浏览 1 评论
3613 浏览 6 评论
5990 浏览 21 评论
940浏览 4评论
1317浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
585浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1304浏览 3评论
1362浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-26 09:20 , Processed in 1.524599 second(s), Total 94, Slave 77 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号