Racism in America dates way back, but it helps to understand its origins. Originally, as the need for a larger labor market in N. America grew, white indentured servants worked alongside black slaves. While indentured servants labored for a fixed number of years before moving on, blacks were typically denied this opportunity; however, landowners, slaveowners, and the ascendant interests of the emerging colonial elite feared the potentiality of whites and blacks banding together against the harsh, miserable conditions confronting them. This fear wasn't necessarily unfounded either: in 1676 former indentured servants, including poor whites and blacks, fomented and engaged in a rebellion against Virginian governor William Berkeley (who had to return to Britain) and torched Jamestown, then the capital of the colony. Now, it should be noted that one of the primary causes for the revolt was Berkeley's reluctance to retaliate against a series of attacks made by Native Americans against the colony, which resulted in groups of whites and blacks attacking and displacing the surrounding Native population.
It was enough to strike fear into the minds of the ruling colonial class though, who swiftly concluded that a united underclass of poor whites and blacks would threaten their livelihoods and standing. As prices for English servants rose and that of Africans became less expensive, indentured servanthood declined, soon to be replaced by the institutionalization of racial slavery. In order to guard against future acts of solidarity between whites and blacks, the land and slave owning class sought to "elevate" the status of poor whites by introducing notions of racial superiority and inferiority - whites occupying the former, blacks the latter. Yet both whites and blacks suffered for it (the latter more so than the former), as unity between the two weakened and frayed, permitting the upper-classes enough maneuverability to manipulate and exploit both. While efforts to bridge the "divide" were attempted (populist Thomas E. Watson urged poor whites and poor blacks to unite around their collective economic self-interests before becoming a white supremacist himself by the turn of the 20th-century), these either collapsed under the weight of existing attitudes and prejudices or were co-opted and later disbanded by the Democratic and Republican parties, who couldn't tolerate a united front between blacks and whites.
Racism serves a very specific purpose, which is the division of the laboring class along racial lines and prejudices, preempting any present or future movement that may see blacks, whites, latinos/as, asians, and others come together to utilize their collective weight and strength to pressure ruling-class circles into acquiescing on certain demands or to overthrow the reigning class itself. Capitalism fosters and perpetuates these divisions, that extend even further along gender, sex/sexuality, and religious lines, creating situations where workers might be isolated and weakened by refusing to coordinate or work with others depending on their race, nationality, sex/sexuality, or religion. It serves a useful purpose, and the bourgeoisie exploit it to the fullest extent possible whenever opportunities present themselves. Racism then is a development fostered as a means of keeping the working-class isolated, separated, and lacking in proper modes of organization capable of upsetting - and even overthrowing - the existing social and material factors holding it back.