简体   繁体   English

从微控制器发送命令以通过SPI显示并接收结果

[英]Sending commands from microcontroller to display via SPI and receiving results

Ok, this question might be a little wide as I don't really know where to start with all this. 好的,这个问题可能有点广泛,因为我真的不知道从哪里开始。 I'll try to be clear. 我会努力弄清楚。

I have a mobile phone display with a known display driver for wich I have the data sheet. 我有一个带有已知显示驱动器的手机显示器,因为我有数据表。 This display will communicate with a micro controller (msp430g type) over SPI. 该显示器将通过SPI与微控制器(msp430g型)通信。

Some of the commands sent to the display does not yield a response but some do, the response might be several "bytes" (9 bits of data). 发送到显示器的某些命令不会产生响应,但有些响应会产生几个“字节”(9位数据)。

I first thought that I should have a fifo buffer to which the microcontroller fed commands so that the micro could do other stuff while the command is being shifted out. 我首先以为我应该有一个fifo缓冲区,微控制器向该缓冲区中馈送命令,以便微控制器在移出命令时可以做其他事情。 But I get the feeling that would "disconnect" the command from the possible response in the case where there is a response. 但是我感到在有响应的情况下,命令会与可能的响应“断开连接”。 And I don't know how to deal with that. 而且我不知道该如何处理。

My second thought was to have all commands as functions that did the (write->[read*x]) that the command in question would need. 我的第二个想法是将所有命令作为执行所涉及命令所需的(write-> [read * x])的函数。 But that feels like I will have the micro standing around waiting for the SPI interface way to much. 但这感觉就像我将让微控制器站在等待SPI接口的方式很多。

What is the "normal" thing to do in this case? 在这种情况下,做什么是“正常的”? I guess there are many answers but I'm sure a lot of code has been written that uses some interface to communicate with some device but do other stuff while the interface is "working". 我猜有很多答案,但是我确定已经写了很多代码,使用某些接口与某些设备进行通信,而在接口“正常工作”时执行其他操作。

If there is anything vague about what I'm trying to do, please just let me know and I'll try to clarify. 如果对我想做的事情含糊不清,请让我知道,我会尽力澄清。

SPI is master-slave, so to Rx from the slave (I'm assuming the display will be the slave) you need to transmit a dummy byte of data (so the master is waggling the clock line) and you should get the Rx data clocked in on your Rx (In/Rx/MISO) pin. SPI是主从设备,因此从从设备到Rx(我假设显示器将是从设备),您需要传输一个虚拟字节的数据(因此,主设备会摆动时钟线),您应该获取Rx数据在您的Rx(In / Rx / MISO)引脚上计时。

If there is a hardware SPI interface that can handle this autonomously then you can leave it all to work in the background & should get an interrupt when it's finished. 如果有一个硬件SPI接口可以自动处理该问题,那么您可以将其全部留在后台运行,并在完成时得到一个中断。

I can't speak for the MSP but on the Coldfire the SPI hardware can be loaded with some stuff to Tx/Rx and will go and do it, in your example you would append a dummy byte to the end of the Tx data and the reply byte would then be in the last slot in the RX buffer when the "ready" interrupt happened. 我不能代表MSP,但是在Coldfire上,SPI硬件可以向Tx / Rx加载一些东西,并且可以执行此操作,在您的示例中,您将在Tx数据的末尾附加一个虚拟字节,并​​且然后,当“就绪”中断发生时,应答字节将位于RX缓冲区的最后一个插槽中。

To schedule the reads and writes in an efficient way, I would recommend the use of interrupts. 为了以高效的方式安排读写,我建议使用中断。 The MSP430 has an interrupt for both when a byte gets sent, and when a byte has been received. MSP430在发送字节和接收字节时都有中断。 When the interrupt fires, load the next byte to be sent (for tx), or store the received byte (for rx). 当中断触发时,加载要发送的下一个字节(对于tx),或存储接收到的字节(对于rx)。 When your command has been sent, you can set a flag for getting a response if you expect one. 发送命令后,如果需要,可以设置一个标志来获取响应。 When you have received a reply you can set a flag for your main loop to process the response. 收到答复后,可以为主循环设置一个标志以处理响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM