如何编写代码,将数据从内部存储器通过SPI主机传输到2个从机 [英] how to write code for transfer data from internal memory via SPI Master to 2 slave

查看:376
本文介绍了如何编写代码,将数据从内部存储器通过SPI主机传输到2个从机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从USB接收数据到Atxmega 128A1的内部存储器

I receive data from USB to the internal memory of Atxmega 128A1

    if ( (SWITCHPORTL.IN & PIN1_bm) == 0 )
    {
        j = 0;
        while (j < NUM_BYTES)
        {
            // Wait till there is unread data in the receive buffer
            while((USART.STATUS & USART_RXCIF_bm) == 0 ){};
            // Read out the received data
            __far_mem_write(j+SDRAM_ADDR, USART.DATA);
            if (j == (NUM_BYTES-1))
            {
                // Toggle LED 1
                LEDPORT.OUTTGL = PIN1_bm;
            }
            j++;
        }
    }

如何从内部存储器中传输数据的代码SPI主机到两个从机,使得偶数字节的数据应该分别发送到两个从机?如何将主机启动到两个从站(多个从站)?

How to write code for transfer data from internal memory via SPI Master to two slaves such that odd and even byte of data should be send separately to two slaves? How to initiate master to two slaves(multiple slaves)?

推荐答案

由于两个从站都连接到同一个总线,一次传输一个数据,您有两个选项可供选择:

Since both slaves are connected to the same bus that only can be transfer one data at a time you have two options to choose from:


  1. 实现一个简单的协议,以便每个从属都知道哪个字节属于给它(例如:具有6位长度和2位接收器代码的一个字节头,或(1 - 从机1,2从机2 - 3从机偶数/奇数)

  2. 使用从机选择引脚和传输一个字节,并确保您不发送下一个,并取消选择第一个接收器,直到发送(计算时钟周期需要多长时间,并且 nop 他们或使用它们其他有用的东西))

  1. implement a simple protocol so that each slave does know, which byte belongs to it. (example: one byte header with 6 bit length and 2 bit receiver code or (1 - slave 1, 2 slave 2 - 3 both slaves even/odd)
  2. use slave select pins and transfer a byte and make sure you do not send the next and deselect the first receiver until the old was send (calculate clock cycles how long would it take and nop them or use them for other usefull stuff))

这篇关于如何编写代码,将数据从内部存储器通过SPI主机传输到2个从机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆