I am trying to configure SPI registers using /dev/mem in imx6. I am able to toggle an led by configuring the GPIO registers using /dev/mem but I am unable to configure SPI.
Following steps I have done.
1. using mmap i have mapped the address 0x200C000 and configured ECSPI2_CONREG for chip select 0.
2. using mmap i have mapped the address 0x20E0000 and configured the IOMUX PADS for SPI2
3. using mmap i have mapped the address 0x200C000 again and configured ECSPI2_CONREG. (loaded (ECSPI2_TXDATA) and enaled xch bit in ECSPI2_CONREG.). I am transmitting continuously in a while loop.
4. I am unable to see any transitions on CS signal and no clock is generated on SCLK.
Is the above configuration method correct ?? am I missing any thing in configuring the SPI , I have not configured any clock registers .
If any sample code for SPI initialization is available please provide.
Thanks in advance.
my code :
int spi_fd = open("/dev/mem",O_RDWR|O_SYNC);
if(spi_fd < 0)
{
printf("Can't open /dev/mem\n");
return 1;
}
spi_reg = (unsigned int *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, spi_fd, 0x200C000);
if(spi_reg == NULL) {
printf("Can't mmap1\n");
return 1;
}
for(i =0; i<10; i++)
{
printf("value = %x\n", spi_reg[i]);
}
/* Configuring SPI*/
spi_reg[2] = 0 ;
spi_reg[2] = 0x7000f1 ;
/* mapping IOMUX*/
spi_reg = (unsigned int *) mmap(0, (2*getpagesize()), PROT_READ|PROT_WRITE, MAP_SHARED, spi_fd, 0x20e0000);
if(spi_reg == NULL)
{
printf("Can't mmap2\n");
return 1;
}
spi_reg[517] = 0x02 ;
spi_reg[516] = 0x02 ;
spi_reg[518] = 0x02 ;
spi_reg[519] = 0x02 ;
spi_reg[158] = 0x02 ;
spi_reg[159] = 0x02 ;
spi_reg[160] = 0x02 ;
spi_reg[161] = 0x02 ;
/* Again mapping SPI registers */
spi_reg = (unsigned int *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, spi_fd, 0x200c000);
if(spi_reg == NULL)
{
printf("Can't mmap3\n");
return 1;
}
spi_reg[1] = 0x21 ;
spi_reg[9] = 0x21 ;
spi_reg[2] = 0x7000f1 ;
spi_reg[3] = 0xF00 ;
while(1)
{
spi_reg[1] = 0x21 ;
spi_reg[9] = 0x21 ;
/* xch enable */
spi_reg[2] = 0x7000f5 ;
sleep(1);
spi_reg[6] = 0x80 ;
printf("data sent\n");
}
Hi vijesh
for simple sample code for SPI initialization one can look at Github SDK
https://github.com/backenklee/swp-report/tree/master/iMX6_Platform_SDK
and spi example in unit tests (folder /mxc_spi_test):
imx-test
www.nxp.com/lgfiles/NMG/MAD/YOCTO/imx-test-5.7.tar.gz
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------