-> In SOC every peripheral has its own indivisual base address that is defined by design team.
-> Suppose peripheral base address
SPI 0x3FFA0000
I2C 0x3EAB0000
WDT 0x4ACD0000
-> And inside peripheral each register has indivisual address that is called offset address.
-> so If we want to configure control register of SPI,
then check what is the offset address for control register into the specification of SPI document.
Assume offset address for control register is 0x004 then complete address is
full address = base address of SPI + offset address of control register .
= 0x3FFA0000 + 0x004
= 0x3FFA0004
-> for that we can write very simple code of C with using pointer.
STEPS
1) first define the base address of peripheral and registers offset address.
example : #define SPI_BASE_ADDR 0x3FFA0000
#define SPI_CONTROL_REG ((unsigned volatile int *)(SPI_BASE_ADDR + 0x00000004)
And this statements should be outside of main program of c testcase.
2) Now using pointer write data on that address which you want to update.
suppose data is 32 bit value 0xA00003FC
so write operation will happen with this command.
*SPI_CONTROL_REG = 0xA00003FC ;
this command will write 0xA00003FC on to the spi control register.
And this statements should be inside of main program of c testcase.
-> Suppose peripheral base address
SPI 0x3FFA0000
I2C 0x3EAB0000
WDT 0x4ACD0000
-> And inside peripheral each register has indivisual address that is called offset address.
-> so If we want to configure control register of SPI,
then check what is the offset address for control register into the specification of SPI document.
Assume offset address for control register is 0x004 then complete address is
full address = base address of SPI + offset address of control register .
= 0x3FFA0000 + 0x004
= 0x3FFA0004
-> for that we can write very simple code of C with using pointer.
STEPS
1) first define the base address of peripheral and registers offset address.
example : #define SPI_BASE_ADDR 0x3FFA0000
#define SPI_CONTROL_REG ((unsigned volatile int *)(SPI_BASE_ADDR + 0x00000004)
And this statements should be outside of main program of c testcase.
2) Now using pointer write data on that address which you want to update.
suppose data is 32 bit value 0xA00003FC
so write operation will happen with this command.
*SPI_CONTROL_REG = 0xA00003FC ;
this command will write 0xA00003FC on to the spi control register.
And this statements should be inside of main program of c testcase.
This comment has been removed by the author.
ReplyDeleteOne thing which has to be understood is that, an ARM processor has three types of ports. A data, an instruction and a peripheral port. Depending on the complexity of the design the peripherals are either connected on the peripheral port or the data port. The above mentioned sequence applies only when the peripherals are mapped on to the data port through a data bus. Hence, a simple read write done at a location would get reflected on the data bus, which are then routed by a cross bar to the respective peripherals register
ReplyDeletehi sriram what is the difference between periphral port and data port of arm and on which basis the designer will choose the port in both of them?
ReplyDelete