Reputation: 11
I am trying to use the i2c interface of a SCB TS-7500 in order to comunicate it to a microcontroler atmega32. i want to configure the twiclockfrequency, and for that i need to configure the ECONA CAVIUM network acces processor. i cant configure the register of the twiclock frequency in the code in C. I have a program named i2ctemp.c im using it to help me.
This is the address of TWI: reg = map_phys(0x71000020,&fd); and the address of the clock is 0x24; an then for the TWI_CLKDIV the bits 16:8.
I did something like this:
void setbitrate( long bitrate ) {
unsigned bitratediv;
//Calcule of twi clock divider value
//Formule is TwiCLockFreq = PCLK /(2*(TwiClockDivider +1))
bitratediv = (unsigned)(PCLK/(2*bitrate)); //PCLK= 1M and bitrate= 50k
///If bitrate value is less than 16 then do:
if(bitratediv <= 16)
bitratediv = bitrate -1 ;
//FINALLY assigned the value to the register of the TWICLOCK
reg[0x24/sizeof(unsigned)] = bitratediv;
* I just want to know how to get this register "0x24" because this doesn´t work-------------------> reg[0x24/sizeof(unsigned)] = bitratediv; ** }
Thank you for your help
Here is the manual of the ECONA CAVIUM and the program i2ctemp.c (ftp://ftp.embeddedarm.com/ts-arm-sbc/ts-7558-linux/samples/i2ctemp.c)! (http://www.embeddedarm.com/documentation/third-party/ECONA-CNS21XX-HRM-v.1.8.pdf)!
Upvotes: 1
Views: 761
Reputation: 224934
You haven't decsribed your environment, but if it's bare metal and you want to set a memory mapped register at address 0x24, you can simply do:
*(volatile unsigned int *)0x24 = bitratediv;
Most people define a macro something like:
#define mmio(reg) (*(volatile unsigned int *)(register))
So that you can just write:
mmio(0x24) = bitratediv;
In your case, you only want to set the top 8 bits of that register, so something like:
mmio(0x24) = (mmio(0x24) & 0x00FF) | (bitratediv << 8);
is probably what you're looking for.
Upvotes: 2