Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
73
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

410Chapter 10 / The PSoC Prototype

3.Here, we have three options: Create New Project, Clone Project, and Create Design-Based Project. This allows us to create a new part from scratch, use an existing part as the start of a new project, or clone an existing part as a starting point for a new idea. Choose Create new project and give it the name Cy8C27443Test and select the default path, which is under the current users My Documents folder. Press Next and the following dialog will be displayed.

Figure 10-9

4.By default, Assembler is selected, as is the CY8C2744312PVXE part. The characters after the hyphen indicate the part packaging. Since this is the part we will be using you can leave the entry as is. I’ve selected the C language since the compiler is installed on my system. If you haven’t purchased the compiler key, the C language choice will be grayed out. Click the Finish button and you will be taken to the main PSoC Designer screen as shown in Figure 10-10.

Chapter 10 / The PSoC Prototype

411

 

 

Figure 10-10

This is where most of our work will take place. Starting from the left side of the design window we have the available preconfigured features that can be added to the part by highlighting the component, right-clicking the mouse, and choosing Select, which will add the chosen feature to the white area directly above the function schematic. In the middle of the work area is a function schematic, and below that a data sheet showing the used resources by part number. The resource meter on the upper-right side of the screen shows us what part resources are used and available.

5.For our project we need a Dallas 1-Wire interface, a Dallas 3-Wire interface (SPI), an I2C master interface, and a TTL RS-232 interface. Move your cursor to the left side of the screen and select the Digital Comm button bar. Everything we will use is located under this heading. You can scroll by clicking the little down button inside the Digital Comm area. When you reach the bottom, an up button will appear. If you look closely you’ll see there are different versions of the

Chapter 10

412

Chapter 10 / The PSoC Prototype

 

 

same interface; some are hardware and others are software. The best part of using this design approach is that we can always remove a function and try something different.

6.Let’s begin by choosing the I2C interface for interacting with our LCD display. There are two choices for this device. The first is the second choice from the top, I2CHW. This is a hardware implementation of the I2C controller. Directly below that option is the second I2C choice, I2Cm for I2C master. Highlighting and clicking on either of these will display their schematic in the middle of the design screen. If we look we can see that the major difference is the first choice allows us to communicate with I2C master and slave devices, whereas the second choice allows us to only communicate with I2C slave devices. Keeping this in mind, highlight the I2Cm component, right-click your mouse, and choose the Select menu item. This will duplicate the function icon in the white area above the function schematic. It will also update the resource meter to show how much RAM and other chip resources have been used. As you can see in Figure 10-11, our resource usage is minimal.

Figure 10-11

Chapter 10 / The PSoC Prototype

413

 

 

The tabs along the bottom of the design screen present the developer with different types of design information. For example, clicking the SampleCode tab shows an assembler listing on how to interface to a Dallas 1307 clock chip using the I2C interface.

To continue our design we need to allocate pins to our I2C interface. The five colored icons at the right of the topmost toolbar control which design view we are in. The view we are currently in is the User Module view. Let’s change views to the Interconnect view, which is the rightmost icon. Our entire design area has changed to resemble the following.

Chapter 10

Figure 10-12

As you can see, the entire design screen has changed. On the far right side of the screen is an image of the chip. Different colors indicate pin usage. A legend below the image explains what each color of pin represents. In the center we have two different views of the part. The upper view shows how the internal interconnects are configured and to which pins they are connected. The graphic below shows the interconnects in a block view. There is a

414

Chapter 10 / The PSoC Prototype

 

 

maximum of 12 blocks combined for analog and digital (fewer depending on the memory and pin count). On the far left side of the screen from top to bottom are global resource parameters, user module parameters, and the pin parameter list.

1.First, let’s assign a port to our I2C interface. On the left side of the design screen, select User Module Parameters and choose Port_0 for the I2C port. Next, select Port_0_0 for the SDA pin and Port_0_1 for the SCL pin. Now enlarge the view of the chip on the right side of the screen, and you will notice P0 and P1 reflect the new pin definitions, as shown in Figure 10-13.

Figure 10-13

2.We will add in the remaining user modules we need before finishing our part configuration. Let’s switch back to the User Module Selection view and add the following modules: a 1-Wire SW module, a UART module, and an SPIM module. The SPIM is a 3-Wire master module. If you try adding a second UART, a message will be displayed, telling you that there aren’t enough digital blocks available. Each UART uses

Chapter 10 / The PSoC Prototype

415

 

 

two digital blocks and this part only allows a total of four digital blocks.

If we look at our resources we can see we’ve used 3 digital blocks, 0 analog blocks, 18 bytes of RAM, and about 1600 bytes of ROM. We have plenty of memory and resources available to work with. When you’ve finished adding the remaining user modules, your screen should look similar to the following.

Chapter 10

Figure 10-14

3.Now we will switch to the Interconnect view by pressing the rightmost icon on the top toolbar. We will need to place the UART and SPIM user modules in PSoC blocks. To do this, select the UART, right-click the mouse, and select the Place option. You will notice two PSoC blocks contain portions of the UART. Now repeat the same process for the SPIM by selecting the module, right-clicking the mouse, and again choosing the Place option.

416Chapter 10 / The PSoC Prototype

4.Now that we have placed the user modules in PSoC blocks, we need to connect them to global I/O lines, which are called rows. This can be done by selecting the user module parameters and selecting the global line to attach each function to. As you connect the device to the internal PSoC I/O you will see lines drawn from the block device to the associated global I/O line. Once this step is completed each global I/O line needs to be attached to a pin so it can communicate with the outside world.

This may seem like a lot of work and it is. But earlier I stated how flexible the PSoC is, and the reason for so many steps in the process is because of the large amount of flexibility. For example, if you had several blocks that collected data and then converted it to a number to be sent out through the serial bus, you would connect many of your blocks together internally but only have one or two pins for output.

I know this has been hard to follow, so let me suggest that you visit the Cypress MicroSystems web site at www.cypress.com and choose the PSoC product. There are many tutorials and online videos that can quickly bring you up to speed.

When we’ve finished adding the required user modules our design screen will look similar to Figure 10-15.

Chapter 10 / The PSoC Prototype

417

 

 

Figure 10-15

Before leaving the PSoC block designer, run a Design Rule Check from the Tools menu. If there are any major problems, they will be reported when this check is done.

5.The next step to competing the implementation is to switch to the application editor. This the second icon from the left in the group at the right of the uppermost toolbar. Here is where we will add the code specific to our embedded system. Once you’ve switched to the application editor, press F7 or select Build | Build All from the menu. This step will generate all the files associated with the user modules we’ve selected and update the header files and libraries as well. When completed, your screen should look similar to Figure 10-16.

Chapter 10

418

Chapter 10 / The PSoC Prototype

 

 

Figure 10-16

During the build process 30 files were created as was a hex file for download to the PSoC. The files are listed in the box at the left side of the screen. To edit a file simply select the filename and double-click it with your mouse. You’ll also notice there are several different source file types associated with the project. Some are .c files, and others are .asm files. These files contain the source code for the associated user modules. User modules can be written in assembler or C.

The function calls associated with each type of user module can be accessed from the device editor screen (the first icon) by choosing the API tab at the bottom of the screen. Code examples can also be viewed by selecting the SampleCode tab next to the API tab. For this example we will output “Hello World” to the Matrix Orbital LCD display.

Even though there are 30 files associated with the project we will be modifying only one of these files, main.c. Since we communicate via the I2C interface, let’s examine the requirements for setting up and using I2C.

Chapter 10 / The PSoC Prototype

419

 

 

The PSoC I2C Function Library

Since we’ve opted to implement I2C in software the following API function calls are available to us:

I2Cm_Start — This function initializes the I2C interface and PSoC pins.

I2Cm_Stop — Performs no function currently

I2Cm_fReadBytes — Reads one or more bytes from a slave device and writes to a data array

I2Cm_bWriteCBytes — Writes one or more bytes to a slave from a data array

I2Cm_fSendStart — Generates an I2C-bus start condition

I2Cm_fSendRepeatStart — Generates an I2C-bus repeat start condition

I2Cm_SendStop — Sends I2C-bus stop condition

I2Cm_fWrite — Sends a 1-byte bus write and ACK

I2Cm_bRead — Initiates a 1-byte bus write and ACK

For our purposes we will start the I2C interface, send the string “Hello World” to I2C slave address 80 (hex 50), wait for a return ACK from the slave, and stop the I2C interface (in theory). The following listing illustrates how few lines of code are needed to accomplish this task.

Listing 10-1

#include <m8c.h>

// part specific constants and macros

#include "PSoCAPI.h"

// PSoC API definitions for all user modules

BYTE txBuf[12] = "Hello World";

// Create Storage for String

void main()

{

/********************************************************************************** Send "Hello World" to the LK202-25

Chapter 10

Соседние файлы в предмете Электротехника