I have basically understood the basic knowledge of IIC in the previous blog. In fact, I still have a few blind spots, because after I learned 51, I got in touch with the MSP430, and then used 430 as a project, I am not very familiar with ok6410 directly, so I will first list some of my knowledge blind spots ~~ ·
1. When we analyze this program, we need to print the data information in the ROM through the serial port. Therefore, the serial port Initialization is unnecessary (Note: Even the serial port Initialization is performed on gpio, I found that many hardware devices operate on gpio.) The Code is as follows:
Void usart0_gpio_config ()
{
// Port a group
// Bit [31: 28] [] [] [] [] [] [] [] [] []
// Config 0010 0010 0010 0010 0010 0010 0010 0010
// Function rtsn1 ctsn1 rtxd1 rxd1 rtsn0 ctsn0 txd0 rxd0
Rgpacon & = ~ (0x22222222 );
Rgpacon | = (0x22222222 );
RGPAPUD = 0x00; // The Upper/lower resistance is not allowed.
}
2. After the GPIO port is configured, the serial port is configured (the baud rate, 8N1, and so on). I will not repeat the code void UART0_Configration (u32 baud)
{
RULCON0 = 0x03; // 8bit no parity one stop
// --- RUCON0 [0: 3] = 0101: indicates that data is received and sent in the // interrupt generation or query mode, and 1010 or 1111 indicates the // DMA transmission mode.
RUCON0 = 0x805; // The clock source uses PCLK, And the interruption is in the pulse mode. No receiving error occurs.
// The status is interrupted. The transmitting and receiving modes are normal.
RUFCON0 = 0x0; // disable FIFO
RUMCON0 = 0x0; // disable modem interruption in FIFO mode.
RUBRDIV0 = (u32) (PCLK/baud/16)-1); // clock Division
RUDIVSLOT0 = (u32) (float) (PCLK/baud/16)-1)-rUBRDIV0) * 16); // decimal point of the crossover Value
}
3. The next step is the focus of this section, that is, the IIC test.
First, analyze a serial port printing function.
VoidUART_Printf (const char * fmt ,...)
{
Va_list ap; // initialize a pointer to the variable parameter list
Char string [256];
Int I;
Va_start (ap, fmt); // pay the address of the first variable parameter to the ap, that is, the ap points to the beginning of the variable parameter list.
Vsprintf (string, fmt, ap); // convert the variable parameters that fmt and ap point to To A formatted string and put it in the string array. This function is the same as sprintf (), only // The parameter type is different
For (I = 0; string [I]; I ++) // send the formatted string from the serial port
Sendchar (string [I]);
Va_end (ap); // The ap value is 0.
}
The variable parameter list mentioned above is (const char * fmt ,...), "... "variable parameters (multiple variable parameters constitute a list, followed by a dedicated pointer to it), not limited quantity and type
I don't know what the idea of this Code is. For me, I used to have a very low understanding of the VA function. I will not discuss the VA function much in this section, baidu search can find a lot.
While (! (RUTRSTAT0 & 0x2) indicates whether to judge whether it is null. If it is null, run the following command (null indicates that there is no data in the sending buffer. In this case, you can send the carriage return character to the sending buffer)
This is the UTRSTAT0 register.
With this, I believe you understand the above Code without any problems.
The next step is to initialize the IIC. first look at the hardware part.
Then read the corresponding code:
Next, you need to initialize the IIC interrupt and directly upload the code.
The Code cannot be understood. Go back and make up C.
VIC0VECTADDR [intNum] = (unsigned) isr; this is an array pointer
I still have a lot of questions about IIC, but I don't understand it very well. It's mainly about the interrupted part. The interrupted part doesn't know whether it's interrupted only when the server address is matched, let's take a look. I hope you can give some advice and find that your C is really bad ~~~ Make up for it !!!!