AM335X的SPI1只有2个片选,但我要接3个SPI从设备,使用spi1_cs0和spi1_cs1设备可以正常工作,我现在想使用GPMC_CSn1作为一个片选使用再接一个设备,下面是我修改board_am335xevm.c
SPI引脚的初始化(最后一行加入了gpmc_csn1管脚):
static struct pinmux_config spi1_pin_mux[] = {
{"mcasp0_aclkx.spi1_sclk", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
| AM33XX_INPUT_EN},
{"mcasp0_fsx.spi1_d0", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
| AM33XX_PULL_UP | AM33XX_INPUT_EN},
{"mcasp0_axr0.spi1_d1", OMAP_MUX_MODE3 | AM33XX_PULL_ENBL
| AM33XX_INPUT_EN},
{"rmii1_refclk.spi1_cs0", OMAP_MUX_MODE2 | AM33XX_PULL_ENBL
| AM33XX_PULL_UP | AM33XX_INPUT_EN},
{"xdma_event_intr0.spi1_cs1", OMAP_MUX_MODE4 | AM33XX_PULL_ENBL
| AM33XX_PULL_UP | AM33XX_INPUT_EN},
{"gpmc_csn1.gpmc_csn1", OMAP_MUX_MODE0 | AM33XX_PULL_ENBL
| AM33XX_PULL_UP | AM33XX_INPUT_EN},
{NULL, 0},
};
SPI的初始化( .chip_select = 0和 .chip_select = 1 ,这里的片选0和1是怎么和管脚rmii1_refclk.spi1_cs0和xdma_event_intr0.spi1_cs1建立联系的?)
static struct spi_board_info spi_board_info[] = {
{
.modalias = "mcp2515",
// or "mcp2515" depending on your controller
.platform_data = &mcp251x_info,
.irq = 224,
.mode =SPI_MODE_0,
.max_speed_hz = 10000000,
.bus_num = 2,
.chip_select = 0,
},
};
static struct spi_board_info spi_board_info_1[] = {
{
.modalias = "mcp2515",
// or "mcp2515" depending on your controller
.platform_data = &mcp251x_info,
.irq = 223,
.mode =SPI_MODE_0,
.max_speed_hz = 10000000,
.bus_num = 2,
.chip_select = 1,
},
};
static struct spi_board_info spi_board_info_2[] = {
{
.modalias = "mcp2515",
// or "mcp2515" depending on your controller
.platform_data = &mcp251x_info,
.irq = 223,
.mode =SPI_MODE_0,
.max_speed_hz = 10000000,
.bus_num = 2,
.chip_select = 2,
},
注册SPI设备:
}static void spi1_init(int evm_id, int profile)
{
setup_pin_mux(spi1_pin_mux);
spi_register_board_info(spi_board_info,
ARRAY_SIZE(spi_board_info));
spi_register_board_info(spi_board_info_1,
ARRAY_SIZE(spi_board_info_1));
spi_register_board_info(spi_board_info_2,
ARRAY_SIZE(spi_board_info_2));
return;
};
但内核启动后只打印了SPI2.0和SPI2.1,没有SPI2.2
请问我该怎么样扩展SPI的片选?
此帖出自
小平头技术问答
对于AM335X而言,SPI控制器仅支持两个片选信号,CS0和CS1。这两个片选是控制器在读写数据时自动控制的,我们完全可以不用控制器自带的片选信号进行连接在控制器上的从设备的选择,而是自己去决定选择哪个从设备,让spi控制器只进行数据的读写操作。即若使用控制器的片选信号,则配置及读写流程是:
1、配置sck、时钟极性和相位、数据位宽度、CS电平;
2、数据读写。
那么不使用SPI控制器的片选信号,自己控制从器件的选择,则配置及读写流程是:
1、配置用作片选的GPIO,并置正确的电平;
2、配置sck,时钟极性和相位、数据位宽度;
3、控制GPIO选通某个从器件;
4、数据读写
5、使片选信号无效,重复3-5即可
一周热门 更多>