emSPI_I2C_Master_RW | Top Next

emSPI_I2C_Master_RW set up one sequence operation for embedded Master SPI or I2C bus. Since R2019b Library: embeddedCreatorLib ( Dafulai Electronics) / Embedded SPI/I2C Bus Master / emSPI_I2C_Master_RW Description One operation of SPI/I2C bus Data Write/reads is done by one sequence. This one operation contains multiple bytes (words) continuous write/reads. All operations are in serial by Sequences. Maximum 15 Sequences: Seq0 to Seq14 are allowable. Seq0 is the most highest priority, Seq14 is the most lowest priority. Before you set up any sequence, you must make sure bus is in Idle state. The is guaranteed by connecting "En" input port to output port of block "isSPI_I2C_Idle". After all sequences done (actual reading/writings action finish), you must call block "setSPI_I2C2Idle" to set bus to idle state. How to know all sequences done ? Please call block "emSPI_I2CAllDone" Parameters Please double click this block to open parameters dialog below: When we choose Bus Type to I2C bus from drop list, the dialog displays below: Let us explain parameters.
• | Peripheral Number — tell system which SPI/I2C controller peripheral is used. You just choose from drop list items which are from block "emSPI_I2CMasterSetup".
• | Bus Type — tell system which bus is used. You just choose from drop list items: SPI bus and I2C bus.
• | Sequence No — Sequence Number for this transaction. You just choose from drop list items which are from parameter "Max Sequence Qty for SPI or I2C" of block "emSPI_I2CMasterSetup".
• | How to specify SPI CS Port — This is for SPI bus, not I2C bus. It has 2 selections, one is "By physical port name and bit number", the other is "By C language writing variable/macro name".
• | Port Name — It is used when you choose "By physical port name and bit number" for previous parameter. It is which GPIO Port is used for SPI CS. You just choose from drop list items.
• | Port Bit number — It is used when you choose "By C language writing variable/macro name" for parameter "How to specify SPI CS Port". It is which bit number is used for SPI CS. You just choose from drop list items.
• | Target SPI CS C language operation Name — It is used when you choose "By physical port name and bit number" for parameter "How to specify SPI CS Port". It specifies C variable name for accessing SPI CS. Please use quotation mark for variable name.
• | Target SPI CS polarity is Active Low — This is for SPI bus, not I2C bus.If checked, SPI CS will be active low.
• | SPI Bus dummy data — This is for SPI bus, not I2C bus. It has 2 items from drop list. One is "ALL bits Logic high", the other is "ALL bits Logic low". We know actual transmitting data length is equal to received data length for SPI bus. However, the meaningful transmitting data length may be less than received data length. In this situation, we need to transmit dummy data to keep equal data length. In general , we have 2 different dummy data, all logic 1 and all logic 0. All logic 1 means 0xFF for 8 bits bus width or 0xFFFF for 16 bits bus width. All logic 0 means 0x0 for both 8 bits and 16 bits bus width.
• | I2C node address — It is only used for I2C bus, not for SPI bus. It is I2C slave node address you want to access. It is 7 bits or 10 bits address which didn't contain R/W Flag bit.
• | Endian — It is for input/output ports endian when data type's data width is over bus width or bit vector endian.
• | Reading data type — It specifies data type of reading data (Output port data type). It can be scalar or vector. element can be "bool","uint8", "int8","uint16","int16","uint32","int32","single". How many vector elements it has is how many output ports it has.If data output port is vector, please follow * and vector element Qty. For example, [ int8, uint16*2, bool*7] denotes that reading data has 6 bytes, and block has 3 output ports. The 1st output port is "int8" type of scalar. The 2nd output port is "uint16" type of vector with 2 elements. The 3rd output port is "bool" type of vector with 7 elements. Notes: We cannot put any quotation mark in vector or scalar. For example, you cannot use [ "int8", "uint16*2", "bool*7"], You cannot use " [ int8, uint16*2, bool*7]". You must use [ int8, uint16*2, bool*7]. So from this parameter, you can know how many bytes to read for your interesting data. We know, for SPI bus, actual reading data QTY is equal to actual writing data QTY. When interesting reading data QTY is less than interesting writing data QTY for SPI bus, interesting reading data will be the last reading data (the latest data). When interesting reading data QTY is bigger than interesting writing data QTY for SPI bus, the actual writing data will be interesting writing data plus dummy data.
• | Writing data type — It specifies data type of writing data (Input port data type). It can be scalar or vector. element can be "bool","uint8", "int8","uint16","int16","uint32","int32","single". How many vector elements it has is how many output ports it has.If data output port is vector, please follow * and vector element Qty. For example, [ int8, uint16*2, bool*7] denotes that writing data has 6 bytes, and block has 3 input ports. The 1st input port is "int8" type of scalar. The 2nd input port is "uint16" type of vector with 2 elements. The 3rd input port is "bool" type of vector with 7 elements. Notes: We cannot put any quotation mark in vector or scalar. For example, you cannot use [ "int8", "uint16*2", "bool*7"], You cannot use " [ int8, uint16*2, bool*7]". You must use [ int8, uint16*2, bool*7]. So from this parameter, you can know how many bytes to write for your interesting data. We know, for SPI bus, actual reading data QTY is equal to actual writing data QTY. When interesting reading data QTY is less than interesting writing data QTY for SPI bus, interesting reading data will be the last reading data (the latest data). When interesting reading data QTY is bigger than interesting writing data QTY for SPI bus, the actual writing data will be interesting writing data plus dummy data.
Ports Input
• | En — "logical" data type's scalar. "True" means SPI/I2C controller will accept sequence settings and does actual write/read action. And it will make SPI/I2C controller into "busy" state. In general, "En" connects the output port of "isSPI_I2C_Idle" block.
For other data input ports, it depends on parameter "Writing data type". The parameter "Writing data type" vector element QTY is Input data port QTY. Please read parameter "Writing data type" above. and see description below
• | Data1 — vector or scalar. Parameter "Writing data type" vector's first element decides what data type it is. and " *digit" decides vector size
.
• | Data2 — vector or scalar. Parameter "Writing data type" vector's second element decides what data type it is. and " *digit" decides vector size.
• | Data3 — vector or scalar. Parameter "Writing data type" vector's third element decides what data type it is. and " *digit" decides vector size.
......
• | Data n — vector or scalar. Parameter "Writing data type" vector's number n element decides what data type it is. and " *digit" decides vector size.
Outport
• | Done — "logical" data type's scalar. "True" means SPI/I2C bus controller has done this sequence transaction. But it may successes or fails for I2C bus.
• | Success — "logical" data type's scalar. "True" means I2C bus controller has done this sequence transaction successfully. SPI bus has no this output port.
For other data output ports,It depends on parameter "Reading data type". The parameter "Reading data type" vector element QTY is output data port QTY. Please read parameter "Reading data type" above. and see description below
• | Data1 — vector or scalar. Parameter "Reading data type" vector's first element decides what data type it is. and " *digit" decides vector size
.
• | Data2 — vector or scalar. Parameter "Reading data type" vector's second element decides what data type it is. and " *digit" decides vector size.
• | Data3 — vector or scalar. Parameter "Reading data type" vector's third element decides what data type it is. and " *digit" decides vector size.
......
• | Data n — vector or scalar. Parameter "Reading data type" vector's number n element decides what data type it is. and " *digit" decides vector size.
Examples